Submission #84060

# Submission time Handle Problem Language Result Execution time Memory
84060 2018-11-12T15:58:30 Z tjdgus4384 None (KOI16_treeM) C++14
100 / 100
209 ms 36800 KB
#include<cstdio>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int pa[200001], query[500001][3];
int g[200001], s[200001];
string ans[200001];

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

void merge(int x, int y)
{
    pa[find(x)] = find(y);
}

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    pa[1] = 1;
    for(int i = 2;i <= n;i++)
    {
        scanf("%d", &g[i]);
        pa[i] = i;
    }
    for(int i = 1;i < n + q;i++)
    {
        scanf("%d", &query[i][0]);
        if(query[i][0]) scanf("%d %d", &query[i][1], &query[i][2]);
        else scanf("%d", &query[i][1]);
    }
    int t = 0;
    for(int i = n + q - 1;i > 0;i--)
    {
        if(!query[i][0]) merge(query[i][1], g[query[i][1]]);
        else
        {
            if(find(query[i][1]) == find(query[i][2])) ans[t++] = "YES";
            else ans[t++] = "NO";
        }
    }
    for(int i = t - 1;i >= 0;i--)
    {
        cout << ans[i] << "\n";
    }
    return 0;
}

Compilation message

tree.cpp: In function 'int main()':
tree.cpp:24: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:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &g[i]);
         ~~~~~^~~~~~~~~~~~~
tree.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &query[i][0]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
tree.cpp:34:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         if(query[i][0]) scanf("%d %d", &query[i][1], &query[i][2]);
                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tree.cpp:35:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         else scanf("%d", &query[i][1]);
              ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6652 KB Output is correct
2 Correct 8 ms 6780 KB Output is correct
3 Correct 8 ms 6780 KB Output is correct
4 Correct 8 ms 6780 KB Output is correct
5 Correct 8 ms 6780 KB Output is correct
6 Correct 8 ms 6788 KB Output is correct
7 Correct 8 ms 6908 KB Output is correct
8 Correct 8 ms 6908 KB Output is correct
9 Correct 8 ms 6908 KB Output is correct
10 Correct 8 ms 6908 KB Output is correct
11 Correct 8 ms 6908 KB Output is correct
12 Correct 8 ms 6908 KB Output is correct
13 Correct 8 ms 6908 KB Output is correct
14 Correct 8 ms 6908 KB Output is correct
15 Correct 8 ms 6908 KB Output is correct
16 Correct 8 ms 6908 KB Output is correct
17 Correct 8 ms 6908 KB Output is correct
18 Correct 9 ms 6908 KB Output is correct
19 Correct 8 ms 6908 KB Output is correct
20 Correct 8 ms 6908 KB Output is correct
21 Correct 8 ms 6908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6652 KB Output is correct
2 Correct 8 ms 6780 KB Output is correct
3 Correct 8 ms 6780 KB Output is correct
4 Correct 8 ms 6780 KB Output is correct
5 Correct 8 ms 6780 KB Output is correct
6 Correct 8 ms 6788 KB Output is correct
7 Correct 8 ms 6908 KB Output is correct
8 Correct 8 ms 6908 KB Output is correct
9 Correct 8 ms 6908 KB Output is correct
10 Correct 8 ms 6908 KB Output is correct
11 Correct 8 ms 6908 KB Output is correct
12 Correct 8 ms 6908 KB Output is correct
13 Correct 8 ms 6908 KB Output is correct
14 Correct 8 ms 6908 KB Output is correct
15 Correct 8 ms 6908 KB Output is correct
16 Correct 8 ms 6908 KB Output is correct
17 Correct 8 ms 6908 KB Output is correct
18 Correct 9 ms 6908 KB Output is correct
19 Correct 8 ms 6908 KB Output is correct
20 Correct 8 ms 6908 KB Output is correct
21 Correct 8 ms 6908 KB Output is correct
22 Correct 96 ms 9808 KB Output is correct
23 Correct 93 ms 9824 KB Output is correct
24 Correct 90 ms 9824 KB Output is correct
25 Correct 92 ms 9824 KB Output is correct
26 Correct 89 ms 9860 KB Output is correct
27 Correct 89 ms 9860 KB Output is correct
28 Correct 98 ms 9860 KB Output is correct
29 Correct 96 ms 9964 KB Output is correct
30 Correct 94 ms 10112 KB Output is correct
31 Correct 104 ms 10144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 13740 KB Output is correct
2 Correct 185 ms 13740 KB Output is correct
3 Correct 175 ms 13844 KB Output is correct
4 Correct 174 ms 13844 KB Output is correct
5 Correct 180 ms 13844 KB Output is correct
6 Correct 193 ms 13844 KB Output is correct
7 Correct 170 ms 13844 KB Output is correct
8 Correct 180 ms 18348 KB Output is correct
9 Correct 206 ms 19620 KB Output is correct
10 Correct 204 ms 19620 KB Output is correct
11 Correct 209 ms 19620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6652 KB Output is correct
2 Correct 8 ms 6780 KB Output is correct
3 Correct 8 ms 6780 KB Output is correct
4 Correct 8 ms 6780 KB Output is correct
5 Correct 8 ms 6780 KB Output is correct
6 Correct 8 ms 6788 KB Output is correct
7 Correct 8 ms 6908 KB Output is correct
8 Correct 8 ms 6908 KB Output is correct
9 Correct 8 ms 6908 KB Output is correct
10 Correct 8 ms 6908 KB Output is correct
11 Correct 8 ms 6908 KB Output is correct
12 Correct 8 ms 6908 KB Output is correct
13 Correct 8 ms 6908 KB Output is correct
14 Correct 8 ms 6908 KB Output is correct
15 Correct 8 ms 6908 KB Output is correct
16 Correct 8 ms 6908 KB Output is correct
17 Correct 8 ms 6908 KB Output is correct
18 Correct 9 ms 6908 KB Output is correct
19 Correct 8 ms 6908 KB Output is correct
20 Correct 8 ms 6908 KB Output is correct
21 Correct 8 ms 6908 KB Output is correct
22 Correct 96 ms 9808 KB Output is correct
23 Correct 93 ms 9824 KB Output is correct
24 Correct 90 ms 9824 KB Output is correct
25 Correct 92 ms 9824 KB Output is correct
26 Correct 89 ms 9860 KB Output is correct
27 Correct 89 ms 9860 KB Output is correct
28 Correct 98 ms 9860 KB Output is correct
29 Correct 96 ms 9964 KB Output is correct
30 Correct 94 ms 10112 KB Output is correct
31 Correct 104 ms 10144 KB Output is correct
32 Correct 171 ms 13740 KB Output is correct
33 Correct 185 ms 13740 KB Output is correct
34 Correct 175 ms 13844 KB Output is correct
35 Correct 174 ms 13844 KB Output is correct
36 Correct 180 ms 13844 KB Output is correct
37 Correct 193 ms 13844 KB Output is correct
38 Correct 170 ms 13844 KB Output is correct
39 Correct 180 ms 18348 KB Output is correct
40 Correct 206 ms 19620 KB Output is correct
41 Correct 204 ms 19620 KB Output is correct
42 Correct 209 ms 19620 KB Output is correct
43 Correct 185 ms 19620 KB Output is correct
44 Correct 195 ms 19620 KB Output is correct
45 Correct 184 ms 19620 KB Output is correct
46 Correct 191 ms 19620 KB Output is correct
47 Correct 184 ms 19620 KB Output is correct
48 Correct 162 ms 19620 KB Output is correct
49 Correct 175 ms 24416 KB Output is correct
50 Correct 175 ms 30520 KB Output is correct
51 Correct 164 ms 36800 KB Output is correct