#include <cstdio>
#include <vector>
#include <memory.h>
using namespace std;
int V, E, Q;
pair<int, int> region;
vector<pair<int, int> > linklist[701];
bool Check[701];
void dfs(int Node) {
int i;
for (i=0; i<linklist[Node].size(); ++i) {
int Node2 = linklist[Node][i].first, lineNum = linklist[Node][i].second;
if (region.first <= lineNum && lineNum <= region.second) continue;
if (!Check[Node2]) {
Check[Node2] = true;
dfs(Node2);
}
}
}
int dfsAll() {
int i, cnt = 0;
for (i=1; i<=V; ++i) {
if (!Check[i]) {
Check[i] = true;
dfs(i);
++cnt;
}
}
return cnt;
}
int main() {
int i;
scanf("%d %d", &V, &E);
for (i=1; i<=E; ++i) {
int st, ed;
scanf("%d %d", &st, &ed);
linklist[st].push_back(make_pair(ed, i));
linklist[ed].push_back(make_pair(st, i));
}
scanf("%d", &Q);
while (Q--) {
scanf("%d %d", ®ion.first, ®ion.second);
memset(Check, 0, 701);
printf("%d\n", dfsAll());
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1224 KB |
Output is correct |
2 |
Correct |
0 ms |
1224 KB |
Output is correct |
3 |
Correct |
0 ms |
1224 KB |
Output is correct |
4 |
Correct |
0 ms |
1224 KB |
Output is correct |
5 |
Correct |
0 ms |
1224 KB |
Output is correct |
6 |
Correct |
0 ms |
1224 KB |
Output is correct |
7 |
Correct |
0 ms |
1224 KB |
Output is correct |
8 |
Correct |
0 ms |
1224 KB |
Output is correct |
9 |
Correct |
0 ms |
1224 KB |
Output is correct |
10 |
Correct |
0 ms |
1224 KB |
Output is correct |
11 |
Correct |
0 ms |
1224 KB |
Output is correct |
12 |
Correct |
0 ms |
1224 KB |
Output is correct |
13 |
Correct |
0 ms |
1224 KB |
Output is correct |
14 |
Correct |
0 ms |
1224 KB |
Output is correct |
15 |
Correct |
0 ms |
1224 KB |
Output is correct |
16 |
Correct |
0 ms |
1224 KB |
Output is correct |
17 |
Correct |
0 ms |
1224 KB |
Output is correct |
18 |
Correct |
0 ms |
1224 KB |
Output is correct |
19 |
Correct |
0 ms |
1224 KB |
Output is correct |
20 |
Correct |
0 ms |
1224 KB |
Output is correct |
21 |
Correct |
0 ms |
1224 KB |
Output is correct |
22 |
Correct |
0 ms |
1224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
216 ms |
1488 KB |
Output is correct |
2 |
Correct |
208 ms |
1488 KB |
Output is correct |
3 |
Correct |
236 ms |
1620 KB |
Output is correct |
4 |
Correct |
596 ms |
2280 KB |
Output is correct |
5 |
Correct |
572 ms |
2148 KB |
Output is correct |
6 |
Execution timed out |
2500 ms |
2280 KB |
Program timed out |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2500 ms |
2676 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |