voidsolve(){ int T; cin >> T; for (int ts = 0; ts < T; ++ts) { int n, m, a, b; cin >> n >> m >> a >> b; graph.init(n); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; graph.add_edge(u, v); graph.add_edge(v, u); } bool vis[MAXN]; queue<int> q; int a_cnt = n - 2, b_cnt = n - 2;
memset(vis, false, sizeof(bool) * (n + 1)); q.push(a); vis[a] = true; while (!q.empty()) { int cur = q.front(); q.pop(); for (int i = graph.head[cur]; i != -1; i = graph.edge[i].next) { if (!vis[graph.edge[i].to] && graph.edge[i].to != b) { vis[graph.edge[i].to] = true; q.push(graph.edge[i].to); a_cnt--; } } }
memset(vis, false, sizeof(bool) * (n + 1)); q.push(b); vis[b] = true; while (!q.empty()) { int cur = q.front(); q.pop(); for (int i = graph.head[cur]; i != -1; i = graph.edge[i].next) { if (!vis[graph.edge[i].to] && graph.edge[i].to != a) { vis[graph.edge[i].to] = true; q.push(graph.edge[i].to); b_cnt--; } } }