답안 #56863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56863 2018-07-13T00:07:48 Z red1108 트리 (KOI16_treeM) C++17
43 / 100
310 ms 66560 KB
#include <stdio.h>
#include <stack>
using namespace std;
stack<int> ans;
int bumo[200010], input[500010][3], par[200010];
int n, q;
int pfind(int x)
{
    if(par[x]==x) return x;
    return par[x]=pfind(par[x]);
}
void uni(int a, int b)
{
    par[pfind(a)]=pfind(b);
}
int main()
{
    int i, a, b;
    scanf("%d %d", &n, &q);
    par[1]=1;
    for(i=2;i<=n;i++)
    {
        par[i]=i;
        scanf("%d", &bumo[i]);
    }
    for(i=1;i<=q+n-1;i++)
    {
        scanf("%d %d", &input[i][0], &input[i][1]);
        if(input[i][0]==1)
        {
            scanf("%d", &input[i][2]);
        }
    }
    for(i=q+n-1;i>=1;i--)
    {
        if(input[i][0]==1)
        {
            if(pfind(input[i][1])==pfind(input[i][2]))
            {
                ans.push(1);
            }
            else ans.push(0);
        }
        else
        {
            uni(input[i][1],bumo[input[i][1]]);
        }
    }
    while(!ans.empty())
    {
        printf("%s\n",ans.top()==1?"YES":"NO");
        ans.pop();
    }
}

Compilation message

tree.cpp: In function 'int main()':
tree.cpp:18:12: warning: unused variable 'a' [-Wunused-variable]
     int i, a, b;
            ^
tree.cpp:18:15: warning: unused variable 'b' [-Wunused-variable]
     int i, a, b;
               ^
tree.cpp:19: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:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &bumo[i]);
         ~~~~~^~~~~~~~~~~~~~~~
tree.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &input[i][0], &input[i][1]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tree.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &input[i][2]);
             ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 528 KB Output is correct
4 Correct 5 ms 528 KB Output is correct
5 Correct 3 ms 624 KB Output is correct
6 Correct 3 ms 624 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 3 ms 624 KB Output is correct
9 Correct 5 ms 672 KB Output is correct
10 Correct 4 ms 680 KB Output is correct
11 Correct 3 ms 688 KB Output is correct
12 Correct 4 ms 696 KB Output is correct
13 Correct 3 ms 696 KB Output is correct
14 Correct 4 ms 712 KB Output is correct
15 Correct 4 ms 720 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 3 ms 736 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 4 ms 760 KB Output is correct
20 Correct 3 ms 852 KB Output is correct
21 Correct 5 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 528 KB Output is correct
4 Correct 5 ms 528 KB Output is correct
5 Correct 3 ms 624 KB Output is correct
6 Correct 3 ms 624 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 3 ms 624 KB Output is correct
9 Correct 5 ms 672 KB Output is correct
10 Correct 4 ms 680 KB Output is correct
11 Correct 3 ms 688 KB Output is correct
12 Correct 4 ms 696 KB Output is correct
13 Correct 3 ms 696 KB Output is correct
14 Correct 4 ms 712 KB Output is correct
15 Correct 4 ms 720 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 3 ms 736 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 4 ms 760 KB Output is correct
20 Correct 3 ms 852 KB Output is correct
21 Correct 5 ms 852 KB Output is correct
22 Correct 100 ms 4516 KB Output is correct
23 Correct 107 ms 4528 KB Output is correct
24 Correct 104 ms 4576 KB Output is correct
25 Correct 131 ms 4576 KB Output is correct
26 Correct 105 ms 4644 KB Output is correct
27 Correct 103 ms 4752 KB Output is correct
28 Correct 89 ms 4752 KB Output is correct
29 Correct 91 ms 4752 KB Output is correct
30 Correct 88 ms 4828 KB Output is correct
31 Correct 89 ms 4828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 170 ms 14044 KB Output is correct
2 Correct 192 ms 19532 KB Output is correct
3 Correct 173 ms 25132 KB Output is correct
4 Correct 240 ms 30708 KB Output is correct
5 Correct 182 ms 36184 KB Output is correct
6 Correct 171 ms 41840 KB Output is correct
7 Correct 196 ms 47244 KB Output is correct
8 Correct 250 ms 53216 KB Output is correct
9 Correct 310 ms 59564 KB Output is correct
10 Correct 171 ms 63964 KB Output is correct
11 Runtime error 171 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 528 KB Output is correct
4 Correct 5 ms 528 KB Output is correct
5 Correct 3 ms 624 KB Output is correct
6 Correct 3 ms 624 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 3 ms 624 KB Output is correct
9 Correct 5 ms 672 KB Output is correct
10 Correct 4 ms 680 KB Output is correct
11 Correct 3 ms 688 KB Output is correct
12 Correct 4 ms 696 KB Output is correct
13 Correct 3 ms 696 KB Output is correct
14 Correct 4 ms 712 KB Output is correct
15 Correct 4 ms 720 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 3 ms 736 KB Output is correct
18 Correct 4 ms 760 KB Output is correct
19 Correct 4 ms 760 KB Output is correct
20 Correct 3 ms 852 KB Output is correct
21 Correct 5 ms 852 KB Output is correct
22 Correct 100 ms 4516 KB Output is correct
23 Correct 107 ms 4528 KB Output is correct
24 Correct 104 ms 4576 KB Output is correct
25 Correct 131 ms 4576 KB Output is correct
26 Correct 105 ms 4644 KB Output is correct
27 Correct 103 ms 4752 KB Output is correct
28 Correct 89 ms 4752 KB Output is correct
29 Correct 91 ms 4752 KB Output is correct
30 Correct 88 ms 4828 KB Output is correct
31 Correct 89 ms 4828 KB Output is correct
32 Correct 170 ms 14044 KB Output is correct
33 Correct 192 ms 19532 KB Output is correct
34 Correct 173 ms 25132 KB Output is correct
35 Correct 240 ms 30708 KB Output is correct
36 Correct 182 ms 36184 KB Output is correct
37 Correct 171 ms 41840 KB Output is correct
38 Correct 196 ms 47244 KB Output is correct
39 Correct 250 ms 53216 KB Output is correct
40 Correct 310 ms 59564 KB Output is correct
41 Correct 171 ms 63964 KB Output is correct
42 Runtime error 171 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.