답안 #84045

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
84045 2018-11-12T13:41:03 Z tjdgus4384 트리 (KOI16_treeM) C++14
43 / 100
2000 ms 57312 KB
#include<cstdio>
int pa[200001], g[200001];

int find(int x)
{
    if(g[x] == x) return x;
    else return g[x] = find(pa[x]);
}

int main()
{
    int n, q, x, b, c, d;
    scanf("%d %d", &n, &q);
    pa[1] = 1;
    g[1] = 1;
    for(int i = 2;i <= n;i++)
    {
        scanf("%d", &pa[i]);
        g[i] = 1;
    }
    for(int i = 1;i < n + q;i++)
    {
        scanf("%d", &x);
        if(!x)
        {
            scanf("%d", &b);
            g[b] = b;
        }
        else
        {
            scanf("%d %d", &c, &d);
            if(find(c) == find(d)) printf("YES\n");
            else printf("NO\n");
        }
    }
    return 0;
}

Compilation message

tree.cpp: In function 'int main()':
tree.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
tree.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &pa[i]);
         ~~~~~^~~~~~~~~~~~~~
tree.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &x);
         ~~~~~^~~~~~~~~~
tree.cpp:26:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &b);
             ~~~~~^~~~~~~~~~
tree.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &c, &d);
             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 532 KB Output is correct
3 Correct 3 ms 552 KB Output is correct
4 Correct 3 ms 636 KB Output is correct
5 Correct 3 ms 880 KB Output is correct
6 Correct 3 ms 880 KB Output is correct
7 Correct 3 ms 880 KB Output is correct
8 Correct 3 ms 948 KB Output is correct
9 Correct 2 ms 988 KB Output is correct
10 Correct 3 ms 1012 KB Output is correct
11 Correct 3 ms 1024 KB Output is correct
12 Correct 3 ms 1036 KB Output is correct
13 Correct 3 ms 1084 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 3 ms 1136 KB Output is correct
16 Correct 3 ms 1160 KB Output is correct
17 Correct 3 ms 1184 KB Output is correct
18 Correct 3 ms 1208 KB Output is correct
19 Correct 3 ms 1220 KB Output is correct
20 Correct 3 ms 1256 KB Output is correct
21 Correct 4 ms 1276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 532 KB Output is correct
3 Correct 3 ms 552 KB Output is correct
4 Correct 3 ms 636 KB Output is correct
5 Correct 3 ms 880 KB Output is correct
6 Correct 3 ms 880 KB Output is correct
7 Correct 3 ms 880 KB Output is correct
8 Correct 3 ms 948 KB Output is correct
9 Correct 2 ms 988 KB Output is correct
10 Correct 3 ms 1012 KB Output is correct
11 Correct 3 ms 1024 KB Output is correct
12 Correct 3 ms 1036 KB Output is correct
13 Correct 3 ms 1084 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 3 ms 1136 KB Output is correct
16 Correct 3 ms 1160 KB Output is correct
17 Correct 3 ms 1184 KB Output is correct
18 Correct 3 ms 1208 KB Output is correct
19 Correct 3 ms 1220 KB Output is correct
20 Correct 3 ms 1256 KB Output is correct
21 Correct 4 ms 1276 KB Output is correct
22 Correct 80 ms 4120 KB Output is correct
23 Correct 89 ms 6304 KB Output is correct
24 Correct 102 ms 8592 KB Output is correct
25 Correct 87 ms 10820 KB Output is correct
26 Correct 81 ms 12952 KB Output is correct
27 Correct 83 ms 15280 KB Output is correct
28 Correct 83 ms 17528 KB Output is correct
29 Correct 85 ms 19776 KB Output is correct
30 Correct 93 ms 22268 KB Output is correct
31 Correct 86 ms 24384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 243 ms 32632 KB Output is correct
2 Correct 258 ms 37844 KB Output is correct
3 Correct 277 ms 45224 KB Output is correct
4 Correct 273 ms 49448 KB Output is correct
5 Correct 263 ms 55496 KB Output is correct
6 Execution timed out 2048 ms 57312 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 532 KB Output is correct
3 Correct 3 ms 552 KB Output is correct
4 Correct 3 ms 636 KB Output is correct
5 Correct 3 ms 880 KB Output is correct
6 Correct 3 ms 880 KB Output is correct
7 Correct 3 ms 880 KB Output is correct
8 Correct 3 ms 948 KB Output is correct
9 Correct 2 ms 988 KB Output is correct
10 Correct 3 ms 1012 KB Output is correct
11 Correct 3 ms 1024 KB Output is correct
12 Correct 3 ms 1036 KB Output is correct
13 Correct 3 ms 1084 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 3 ms 1136 KB Output is correct
16 Correct 3 ms 1160 KB Output is correct
17 Correct 3 ms 1184 KB Output is correct
18 Correct 3 ms 1208 KB Output is correct
19 Correct 3 ms 1220 KB Output is correct
20 Correct 3 ms 1256 KB Output is correct
21 Correct 4 ms 1276 KB Output is correct
22 Correct 80 ms 4120 KB Output is correct
23 Correct 89 ms 6304 KB Output is correct
24 Correct 102 ms 8592 KB Output is correct
25 Correct 87 ms 10820 KB Output is correct
26 Correct 81 ms 12952 KB Output is correct
27 Correct 83 ms 15280 KB Output is correct
28 Correct 83 ms 17528 KB Output is correct
29 Correct 85 ms 19776 KB Output is correct
30 Correct 93 ms 22268 KB Output is correct
31 Correct 86 ms 24384 KB Output is correct
32 Correct 243 ms 32632 KB Output is correct
33 Correct 258 ms 37844 KB Output is correct
34 Correct 277 ms 45224 KB Output is correct
35 Correct 273 ms 49448 KB Output is correct
36 Correct 263 ms 55496 KB Output is correct
37 Execution timed out 2048 ms 57312 KB Time limit exceeded
38 Halted 0 ms 0 KB -