Submission #2870

#TimeUsernameProblemLanguageResultExecution timeMemory
2870ladown21간선 파괴 (GA5_destroy)C++98
25 / 100
2500 ms2912 KiB
#include <stdio.h> #include <algorithm> #include <queue> #include <vector> using namespace std; const int MAX_E = 130000; const int MAX_V = 800; struct Edge{int a,b;}edge[MAX_E]; Edge inner(int a,int b) {Edge r={a,b};return r;} int Component(int l,int r, int V, int E) { vector<int> G[MAX_V]; for (int k=1; k<=E; k++) { if (l==k) {k=r; continue;} G[edge[k].a].push_back(edge[k].b); G[edge[k].b].push_back(edge[k].a); } int M[MAX_V] = {0}, ret=0; for (int k=1; k<=V; k++) { if (M[k]) continue; queue<int> q; q.push(k); M[k] = 1; while (!q.empty()) { int x=q.front(); q.pop(); int size=G[x].size(); for (int i=0; i<size; i++) { int y=G[x][i]; if (M[y]) continue; M[y] = 1; q.push(y); } } ret++; } return ret; } int main() { int V,E,Q; scanf("%d%d",&V,&E); int u,v; for (int i=1; i<=E; i++) { scanf("%d%d",&u,&v); edge[i] = inner(u,v); } scanf("%d",&Q); while (Q--) { int l,r; scanf("%d%d",&l,&r); printf("%d\n",Component(l,r,V,E)); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...