QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#949370#10179. 입자 가속기KiharaTouma#0 142ms29984kbC++143.1kb2025-03-23 20:53:232025-03-23 20:53:32

Judging History

This is the latest submission verdict.

  • [2025-03-23 20:53:32]
  • Judged
  • Verdict: 0
  • Time: 142ms
  • Memory: 29984kb
  • [2025-03-23 20:53:23]
  • Submitted

answer

//qoj10179
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;
int n, fa[N], ban[N], nw, siz[N], hav[N], stn;
vector<int> g[N];
vector<int> qq[N];
int nt, vis[N];

void initialize(int N, vector<int> A, vector<int> B){
    n = N;
    stn = 1;
    nt = 1;
    for(int i = 1; i <= n; ++ i){
        vector<int> ().swap(g[i]);
        vector<int> ().swap(qq[i]);
        fa[i] = 1;
        ban[i] = siz[i] = 0;
        hav[i] = 0;
        vis[i] = 0;
    }
    for(int i = 0; i < n - 1; ++ i){
        g[A[i]+1].push_back(B[i] + 1);
        g[B[i]+1].push_back(A[i] + 1);
    }
}

int generate(int u, bool res){
    ++ u;
    ++ nt;
    if(res == 1){
        nw -= siz[fa[u]] / 2;
        ++ siz[fa[u]];
        hav[u] = 1;
        nw += siz[fa[u]] / 2;
        return nw;
    }
    ban[u] = 1;
    nw -= siz[fa[u]] / 2;
    static int ss[N], ql[N], qr[N], sm[N];
    int tp = 0;
    for(int i : g[u]){
        if(!ban[i]){
            ss[++tp] = i;
            vector<int> ().swap(qq[tp]);
            qq[tp].push_back(i);
            ql[tp] = qr[tp] = 0;
            vis[i] = nt;
            sm[tp] = 0;
        }
    }
    int ed = 0;
    vis[u] = nt;
    while(ed < tp - 1){
        for(int i = 1; i <= tp; ++ i){
            if(ql[i] <= qr[i]){
                int x = qq[i][ql[i]];
                ++ ql[i];
                for(int y : g[x]){
                    if(!ban[y] && vis[y] != nt){
                        vis[y] = nt;
                        ++ qr[i];
                        qq[i].push_back(y);
                    }
                }
                if(ql[i] > qr[i]){
                    sm[i] = 1;
                    ++ ed;
                }
            }
            if(ed == tp - 1){
                break;
            }
        }
    }
    int lp = fa[u];
    for(int i = 1; i <= tp; ++ i){
        if(sm[i]){
            printf("[%d]: ", i);
            ++ stn;
            for(int j : qq[i]){
                printf("%d ", j);
                fa[j] = stn;
                if(hav[j]){
                    ++ siz[stn];
                    -- siz[lp];
                }
            }
            nw += siz[stn] / 2;
            puts("");
        }
    }
    nw += siz[lp] / 2;
    return nw;
}

#ifndef ONLINE_JUDGE

void my_assert(bool x){
    if (!x){
        puts("Wrong input");
        exit(0);
    }
}
 
int main(){
    int N, Q;
    my_assert(scanf("%d %d", &N, &Q) == 2);
    
    std::vector<int> A(N-1), B(N-1);
    for (int i=0;i<N-1;i++){
        my_assert(scanf("%d %d", &A[i], &B[i]) == 2);
        my_assert(0 <= A[i] && A[i] <= N-1);
        my_assert(0 <= B[i] && B[i] <= N-1);
        my_assert(A[i] != B[i]);
    }
    
    initialize(N, A, B);
    std::vector<int> ans(Q);
    std::vector<int> V(Q), R(Q);
    for (int i=0;i<Q;i++){
        my_assert(scanf("%d %d", &V[i], &R[i]) == 2);
        my_assert(0 <= V[i] && V[i] <= N-1);
        my_assert(R[i] == 0 || R[i] == 1);
        ans[i] = generate(V[i], R[i]==1);
        printf("%d\n", ans[i]);
    }
    cerr << stn << '\n';
}

#endif

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 9
Accepted
time: 2ms
memory: 17548kb

input:

2 2
0 1
0 1
1 1

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
1

result:

ok 3 lines

Test #2:

score: 0
Wrong Answer
time: 1ms
memory: 16864kb

input:

6 5
0 1
0 2
0 3
3 4
3 5
1 1
5 1
0 0
4 1
3 1

output:

Unauthorized output

result:

wrong answer 1st lines differ - expected: 'b74500f8-4e8b-4d58-879e-82e9596bfa16', found: 'Unauthorized output'

Subtask #2:

score: 0
Wrong Answer

Test #12:

score: 0
Wrong Answer
time: 72ms
memory: 29352kb

input:

200000 200000
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51...

output:

Unauthorized output

result:

wrong answer 1st lines differ - expected: 'b74500f8-4e8b-4d58-879e-82e9596bfa16', found: 'Unauthorized output'

Subtask #3:

score: 0
Wrong Answer

Test #25:

score: 20
Accepted
time: 68ms
memory: 28156kb

input:

200000 200000
155284 18435
18435 57260
57260 88628
88628 170108
57260 126961
170108 72596
72596 46044
170108 28914
46044 177699
155284 143087
18435 161808
177699 107693
18435 74517
28914 77075
126961 116303
177699 26806
74517 43330
77075 188898
126961 45168
57260 93201
93201 198698
77075 36077
57260...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
...

result:

ok 200001 lines

Test #26:

score: 20
Accepted
time: 66ms
memory: 29096kb

input:

200000 200000
20214 166890
166890 39782
39782 160973
160973 71809
71809 84135
84135 193485
193485 191907
191907 73443
73443 172846
172846 62828
62828 30539
30539 148834
148834 105784
105784 31379
31379 169920
169920 104347
104347 46092
46092 84919
84919 105144
105144 181794
181794 12834
12834 103965...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
...

result:

ok 200001 lines

Test #27:

score: 20
Accepted
time: 68ms
memory: 29984kb

input:

200000 200000
13661 52989
13661 191413
13661 183385
13661 180760
13661 45914
13661 154223
13661 92602
13661 143465
13661 115429
13661 35411
13661 110883
13661 100122
13661 103685
13661 173658
13661 44682
13661 142827
13661 182193
13661 191182
13661 101940
13661 117063
13661 92502
13661 128744
13661 ...

output:

b74500f8-4e8b-4d58-879e-82e9596bfa16
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11
12
12
13
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
21
22
22
23
23
24
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
34
35
35
36
36
37
37
38
38
39
39
40
40
41
41
42
42
43
43
44
44
45
45
46
46
47
...

result:

ok 200001 lines

Test #28:

score: 0
Wrong Answer
time: 65ms
memory: 28448kb

input:

200000 200000
59493 126128
59493 29185
29185 51986
126128 194222
194222 36489
29185 13257
59493 88509
29185 5290
88509 117426
88509 9059
117426 14322
88509 79181
14322 145100
59493 177676
36489 59023
14322 107337
107337 91882
59023 62581
88509 79723
62581 111878
88509 99587
107337 50973
107337 72208...

output:

Unauthorized output

result:

wrong answer 1st lines differ - expected: 'b74500f8-4e8b-4d58-879e-82e9596bfa16', found: 'Unauthorized output'

Subtask #4:

score: 0
Wrong Answer

Test #37:

score: 0
Wrong Answer
time: 142ms
memory: 29644kb

input:

200000 200000
124028 117993
117993 64181
124028 176900
64181 197782
124028 153477
153477 179542
64181 191368
197782 55523
64181 36078
153477 108486
117993 169125
179542 68449
124028 153826
124028 142937
36078 65258
36078 28508
68449 114673
191368 17655
197782 90991
176900 48570
191368 6324
153826 18...

output:

Unauthorized output

result:

wrong answer 1st lines differ - expected: 'b74500f8-4e8b-4d58-879e-82e9596bfa16', found: 'Unauthorized output'

Subtask #5:

score: 0
Wrong Answer

Test #51:

score: 0
Wrong Answer
time: 134ms
memory: 29700kb

input:

200000 200000
75490 97148
75490 176817
75490 80168
75490 73425
97148 38334
80168 199950
73425 5116
5116 154439
80168 90246
154439 5305
154439 101118
101118 28211
90246 91284
75490 103069
80168 85099
176817 55430
38334 31693
55430 28292
80168 163565
163565 196782
28211 194198
28292 163487
73425 30097...

output:

Unauthorized output

result:

wrong answer 1st lines differ - expected: 'b74500f8-4e8b-4d58-879e-82e9596bfa16', found: 'Unauthorized output'