#include <stdio.h>
#include <vector>
using namespace std;
const int MAXN = 700;
vector<pair<int,int> > data[MAXN + 1];
int q[MAXN + 1];
int r = -1, f = -1;
bool ch[MAXN + 1];
int main ()
{
int n, m;
scanf ("%d %d", &n, &m);
for (int i = 0; i < m; ++i)
{
int x, y;
scanf ("%d %d", &x, &y);
data[x - 1].push_back (make_pair (y - 1, i + 1));
data[y - 1].push_back (make_pair (x - 1, i + 1));
}
int k;
scanf ("%d", &k);
for (int i = 0; i < k; ++i)
{
int x, y;
scanf ("%d %d", &x, &y);
int sol = 0;
for (int i = 0; i < n; ++i)
{
if (!ch[i])
{
int j;
++sol;
r = f = -1;
q[++r] = i;
ch[i] = true;
while (r > f)
{
j = q[++f];
for (int k = 0; k < data[j].size (); ++k)
{
if (x <= data[j][k].second && data[j][k].second <= y)
continue;
if (!ch[data[j][k].first])
{
ch[data[j][k].first] = true;
q[++r] = data[j][k].first;
}
}
}
}
}
printf ("%d\n", sol);
for (int i = 0; i < n; ++i)
{
ch[i] = false;
}
}
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 |
224 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 |
528 ms |
2280 KB |
Output is correct |
5 |
Correct |
520 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 |
- |