structVertex { int color = -1; vector<int> neighbors; };
boolcheck(Vertex *graph, int N){ int root = 1; do { queue<int> visited; visited.push(root); graph[root].color = 0; while (!visited.empty()) { int root = visited.front(); visited.pop(); vector<int> neighbors = graph[root].neighbors; for (int i = 0; i < neighbors.size(); i++) { if (graph[neighbors[i]].color == -1) { graph[neighbors[i]].color = 1 - graph[root].color; visited.push(neighbors[i]); } elseif (graph[neighbors[i]].color == graph[root].color) returnfalse; } }
root = 0; for (int i = 1; i < N + 1; i++) if (graph[i].color == -1) { root = i; break; } } while (root != 0);
returntrue; }
intmain(){ int T = 0; cin >> T; for (int i = 0; i < T; i++) { int N = 0, M = 0; cin >> N >> M; Vertex *graph = new Vertex[N + 1]; for (int j = 0; j < M; j++) { int a = 0, b = 0; cin >> a >> b; graph[a].neighbors.push_back(b); graph[b].neighbors.push_back(a); }