Submission #84059

# Submission time Handle Problem Language Result Execution time Memory
84059 2018-11-12T15:57:37 Z tjdgus4384 None (KOI16_treeM) C++14
71 / 100
248 ms 66560 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";
    }
}

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 8 ms 6648 KB Output is correct
2 Correct 10 ms 6908 KB Output is correct
3 Correct 8 ms 6908 KB Output is correct
4 Correct 8 ms 6908 KB Output is correct
5 Correct 8 ms 6908 KB Output is correct
6 Correct 8 ms 6908 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 9 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 10 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 8 ms 6648 KB Output is correct
2 Correct 10 ms 6908 KB Output is correct
3 Correct 8 ms 6908 KB Output is correct
4 Correct 8 ms 6908 KB Output is correct
5 Correct 8 ms 6908 KB Output is correct
6 Correct 8 ms 6908 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 9 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 10 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 92 ms 9952 KB Output is correct
23 Correct 93 ms 9968 KB Output is correct
24 Correct 94 ms 9968 KB Output is correct
25 Correct 93 ms 9968 KB Output is correct
26 Correct 93 ms 9968 KB Output is correct
27 Correct 92 ms 9972 KB Output is correct
28 Correct 91 ms 9976 KB Output is correct
29 Correct 89 ms 9976 KB Output is correct
30 Correct 148 ms 10016 KB Output is correct
31 Correct 100 ms 10020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 245 ms 13876 KB Output is correct
2 Correct 181 ms 13876 KB Output is correct
3 Correct 204 ms 13876 KB Output is correct
4 Correct 175 ms 13876 KB Output is correct
5 Correct 196 ms 13876 KB Output is correct
6 Correct 206 ms 13876 KB Output is correct
7 Correct 197 ms 13876 KB Output is correct
8 Correct 181 ms 18388 KB Output is correct
9 Correct 180 ms 24632 KB Output is correct
10 Correct 213 ms 29044 KB Output is correct
11 Correct 178 ms 34468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 6648 KB Output is correct
2 Correct 10 ms 6908 KB Output is correct
3 Correct 8 ms 6908 KB Output is correct
4 Correct 8 ms 6908 KB Output is correct
5 Correct 8 ms 6908 KB Output is correct
6 Correct 8 ms 6908 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 9 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 10 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 92 ms 9952 KB Output is correct
23 Correct 93 ms 9968 KB Output is correct
24 Correct 94 ms 9968 KB Output is correct
25 Correct 93 ms 9968 KB Output is correct
26 Correct 93 ms 9968 KB Output is correct
27 Correct 92 ms 9972 KB Output is correct
28 Correct 91 ms 9976 KB Output is correct
29 Correct 89 ms 9976 KB Output is correct
30 Correct 148 ms 10016 KB Output is correct
31 Correct 100 ms 10020 KB Output is correct
32 Correct 245 ms 13876 KB Output is correct
33 Correct 181 ms 13876 KB Output is correct
34 Correct 204 ms 13876 KB Output is correct
35 Correct 175 ms 13876 KB Output is correct
36 Correct 196 ms 13876 KB Output is correct
37 Correct 206 ms 13876 KB Output is correct
38 Correct 197 ms 13876 KB Output is correct
39 Correct 181 ms 18388 KB Output is correct
40 Correct 180 ms 24632 KB Output is correct
41 Correct 213 ms 29044 KB Output is correct
42 Correct 178 ms 34468 KB Output is correct
43 Correct 196 ms 40644 KB Output is correct
44 Correct 200 ms 46708 KB Output is correct
45 Correct 248 ms 52904 KB Output is correct
46 Correct 179 ms 59012 KB Output is correct
47 Correct 173 ms 65072 KB Output is correct
48 Runtime error 167 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.
49 Halted 0 ms 0 KB -