This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |