# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
7760 |
2014-08-18T11:06:44 Z |
tncks0121 |
간선 파괴 (GA5_destroy) |
C++ |
|
64 ms |
5416 KB |
#include <stdio.h>
#include <memory.h>
#include <algorithm>
using namespace std;
const int N_ = 1005;
const int M_ = 200005;
int N, M, Q;
short A[M_], B[M_];
short parent[N_];
short rank[N_];
void init() { for(int i = 1; i <= N; i++) parent[i] = i, rank[i] = 1; }
short get(short u) {
int r = u;
while(parent[r] != r) r = parent[r];
while(u != r) {
int p = parent[u];
parent[u] = r;
u = p;
}
return r;
}
bool merge (short a, short b) {
a = get(a); b = get(b);
if(rank[a] < rank[b]) {
parent[a] = b;
}else if(rank[a] > rank[b]) {
parent[b] = a;
}else {
parent[b] = a;
++rank[a];
}
return a != b;
}
int F[N_], FN, R[N_], RN;
int EF[M_], ER[M_];
short T[N_][N_];
int main () {
int i, j, k;
scanf("%d%d", &N, &M);
for(i = 1; i <= M; i++) scanf("%d%d", A+i, B+i);
init();
for(i = 1; i <= M; i++) if(merge(A[i], B[i])) F[++FN] = i;
for(i = 1, j = 1; i <= M; i++) {
EF[i] = j;
if(F[j] == i) ++j;
}
init();
for(i = M; i > 0; i--) if(merge(A[i], B[i])) R[++RN] = i;
for(i = M, j = 1; i > 0; i--) {
ER[i] = j;
if(R[j] == i) ++j;
}
for(i = 1; i <= FN+1; i++) {
int cnt = N;
init();
for(j = 1; j < i; j++) if(merge(A[F[j]], B[F[j]])) --cnt;
for(j = 1; j <= RN; j++) {
T[i][j] = cnt;
if(merge(A[R[j]], B[R[j]])) --cnt;
}
T[i][RN+1] = cnt;
}
scanf("%d", &Q);
while(Q--) {
int x, y, ret = N;
scanf("%d%d", &x, &y);
x = EF[x];
y = ER[y];
if(x > 0 && y > 0) ret = T[x][y];
printf("%d\n", ret);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5416 KB |
Output is correct |
2 |
Correct |
0 ms |
5416 KB |
Output is correct |
3 |
Correct |
0 ms |
5416 KB |
Output is correct |
4 |
Correct |
0 ms |
5416 KB |
Output is correct |
5 |
Correct |
0 ms |
5416 KB |
Output is correct |
6 |
Correct |
0 ms |
5416 KB |
Output is correct |
7 |
Correct |
0 ms |
5416 KB |
Output is correct |
8 |
Correct |
0 ms |
5416 KB |
Output is correct |
9 |
Correct |
0 ms |
5416 KB |
Output is correct |
10 |
Correct |
0 ms |
5416 KB |
Output is correct |
11 |
Correct |
0 ms |
5416 KB |
Output is correct |
12 |
Correct |
0 ms |
5416 KB |
Output is correct |
13 |
Correct |
0 ms |
5416 KB |
Output is correct |
14 |
Correct |
0 ms |
5416 KB |
Output is correct |
15 |
Correct |
0 ms |
5416 KB |
Output is correct |
16 |
Correct |
0 ms |
5416 KB |
Output is correct |
17 |
Correct |
0 ms |
5416 KB |
Output is correct |
18 |
Correct |
0 ms |
5416 KB |
Output is correct |
19 |
Correct |
0 ms |
5416 KB |
Output is correct |
20 |
Correct |
0 ms |
5416 KB |
Output is correct |
21 |
Correct |
0 ms |
5416 KB |
Output is correct |
22 |
Correct |
0 ms |
5416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5416 KB |
Output is correct |
2 |
Correct |
8 ms |
5416 KB |
Output is correct |
3 |
Correct |
12 ms |
5416 KB |
Output is correct |
4 |
Correct |
16 ms |
5416 KB |
Output is correct |
5 |
Correct |
20 ms |
5416 KB |
Output is correct |
6 |
Correct |
24 ms |
5416 KB |
Output is correct |
7 |
Correct |
20 ms |
5416 KB |
Output is correct |
8 |
Correct |
24 ms |
5416 KB |
Output is correct |
9 |
Correct |
8 ms |
5416 KB |
Output is correct |
10 |
Correct |
8 ms |
5416 KB |
Output is correct |
11 |
Correct |
8 ms |
5416 KB |
Output is correct |
12 |
Correct |
20 ms |
5416 KB |
Output is correct |
13 |
Correct |
20 ms |
5416 KB |
Output is correct |
14 |
Correct |
20 ms |
5416 KB |
Output is correct |
15 |
Correct |
8 ms |
5416 KB |
Output is correct |
16 |
Correct |
8 ms |
5416 KB |
Output is correct |
17 |
Correct |
4 ms |
5416 KB |
Output is correct |
18 |
Correct |
4 ms |
5416 KB |
Output is correct |
19 |
Correct |
0 ms |
5416 KB |
Output is correct |
20 |
Correct |
0 ms |
5416 KB |
Output is correct |
21 |
Correct |
0 ms |
5416 KB |
Output is correct |
22 |
Correct |
0 ms |
5416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
5416 KB |
Output is correct |
2 |
Correct |
48 ms |
5416 KB |
Output is correct |
3 |
Correct |
56 ms |
5416 KB |
Output is correct |
4 |
Correct |
48 ms |
5416 KB |
Output is correct |
5 |
Correct |
40 ms |
5416 KB |
Output is correct |
6 |
Correct |
64 ms |
5416 KB |
Output is correct |
7 |
Correct |
32 ms |
5416 KB |
Output is correct |
8 |
Correct |
44 ms |
5416 KB |
Output is correct |
9 |
Correct |
32 ms |
5416 KB |
Output is correct |
10 |
Correct |
28 ms |
5416 KB |
Output is correct |
11 |
Correct |
36 ms |
5416 KB |
Output is correct |
12 |
Correct |
56 ms |
5416 KB |
Output is correct |
13 |
Correct |
48 ms |
5416 KB |
Output is correct |
14 |
Correct |
44 ms |
5416 KB |
Output is correct |
15 |
Correct |
36 ms |
5416 KB |
Output is correct |
16 |
Correct |
32 ms |
5416 KB |
Output is correct |
17 |
Correct |
28 ms |
5416 KB |
Output is correct |
18 |
Correct |
28 ms |
5416 KB |
Output is correct |
19 |
Correct |
24 ms |
5416 KB |
Output is correct |
20 |
Correct |
20 ms |
5416 KB |
Output is correct |
21 |
Correct |
16 ms |
5416 KB |
Output is correct |
22 |
Correct |
12 ms |
5416 KB |
Output is correct |