#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef pair <int,int> ppair;
vector <ppair> A[701];
queue <int> q;
int V, E, Q, Check[701], L, R, X;
void input(void)
{
int i, u, v;
scanf("%d %d",&V,&E);
for(i=1 ; i<=E ; i++)
{
scanf("%d %d",&u,&v);
A[u].push_back(make_pair(v,i));
A[v].push_back(make_pair(u,i));
}
scanf("%d",&Q);
}
void BFS(int start)
{
int i, j, now;
Check[start]=X;
q.push(start);
while(!q.empty())
{
now=q.front();
q.pop();
j=A[now].size();
for(i=0 ; i<j ; i++)
if(!(L<=A[now][i].second && A[now][i].second<=R) && Check[A[now][i].first]!=X)
{
Check[A[now][i].first]=X;
q.push(A[now][i].first);
}
}
}
void process(void)
{
int i, j, cnt;
for(i=1 ; i<=Q ; i++)
{
X=i;
cnt=0;
scanf("%d %d",&L,&R);
for(j=1 ; j<=V ; j++)
if(Check[j]!=X)
{
cnt++;
BFS(j);
}
printf("%d\n",cnt);
}
}
int main(void)
{
input();
process();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1256 KB |
Output is correct |
2 |
Correct |
0 ms |
1256 KB |
Output is correct |
3 |
Correct |
0 ms |
1256 KB |
Output is correct |
4 |
Correct |
0 ms |
1256 KB |
Output is correct |
5 |
Correct |
0 ms |
1256 KB |
Output is correct |
6 |
Correct |
0 ms |
1256 KB |
Output is correct |
7 |
Correct |
0 ms |
1256 KB |
Output is correct |
8 |
Correct |
0 ms |
1256 KB |
Output is correct |
9 |
Correct |
0 ms |
1256 KB |
Output is correct |
10 |
Correct |
0 ms |
1256 KB |
Output is correct |
11 |
Correct |
0 ms |
1256 KB |
Output is correct |
12 |
Correct |
0 ms |
1256 KB |
Output is correct |
13 |
Correct |
0 ms |
1256 KB |
Output is correct |
14 |
Correct |
0 ms |
1256 KB |
Output is correct |
15 |
Correct |
0 ms |
1256 KB |
Output is correct |
16 |
Correct |
0 ms |
1256 KB |
Output is correct |
17 |
Correct |
0 ms |
1256 KB |
Output is correct |
18 |
Correct |
0 ms |
1256 KB |
Output is correct |
19 |
Correct |
0 ms |
1256 KB |
Output is correct |
20 |
Correct |
0 ms |
1256 KB |
Output is correct |
21 |
Correct |
0 ms |
1256 KB |
Output is correct |
22 |
Correct |
0 ms |
1256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
172 ms |
1520 KB |
Output is correct |
2 |
Correct |
164 ms |
1520 KB |
Output is correct |
3 |
Correct |
184 ms |
1652 KB |
Output is correct |
4 |
Correct |
436 ms |
2312 KB |
Output is correct |
5 |
Correct |
432 ms |
2180 KB |
Output is correct |
6 |
Execution timed out |
2500 ms |
2312 KB |
Program timed out |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2500 ms |
2708 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |