답안 #77756

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
77756 2018-09-30T08:36:04 Z ansol4328 트리 (KOI16_treeM) C++
71 / 100
206 ms 66560 KB
#include<stdio.h>
#include<memory.h>

using namespace std;

struct uf
{
    int p[200002];
    uf()
    {
        memset(p,-1,sizeof(p));
    }
    int f(int v)
    {
        if(p[v]==-1) return v;
        p[v]=f(p[v]);
        return p[v];
    }
    bool same(int a, int b)
    {
        a=f(a);
        b=f(b);
        if(a==b) return true;
        return false;
    }
    void u(int a, int b)
    {
        a=f(a);
        b=f(b);
        if(a==b) return;
        p[a]=b;
    }
};

int n, q;
int p[200002];
int query[400002][3], cnt;
bool res[200002];
uf T;

int main()
{
    scanf("%d %d",&n,&q);
    for(int i=2 ; i<=n ; i++) scanf("%d",&p[i]);
    for(int i=1 ; i<=n-1+q ; i++)
    {
        scanf("%d %d",&query[i][0],&query[i][1]);
        if(query[i][0]) scanf("%d",&query[i][2]);
    }
    for(int i=n-1+q ; i>=1 ; i--)
    {
        if(query[i][0]==0) T.u(p[query[i][1]],query[i][1]);
        else res[cnt++]=T.same(query[i][1],query[i][2]);
    }
    for(int i=q-1 ; i>=0 ; i--) printf("%s\n",res[i] ? "YES" : "NO");
    return 0;
}

Compilation message

tree.cpp: In function 'int main()':
tree.cpp:43: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:44:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=2 ; i<=n ; i++) scanf("%d",&p[i]);
                               ~~~~~^~~~~~~~~~~~
tree.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&query[i][0],&query[i][1]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tree.cpp:48:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         if(query[i][0]) scanf("%d",&query[i][2]);
                         ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 3 ms 1164 KB Output is correct
3 Correct 3 ms 1264 KB Output is correct
4 Correct 4 ms 1304 KB Output is correct
5 Correct 3 ms 1388 KB Output is correct
6 Correct 3 ms 1412 KB Output is correct
7 Correct 3 ms 1452 KB Output is correct
8 Correct 3 ms 1476 KB Output is correct
9 Correct 3 ms 1500 KB Output is correct
10 Correct 3 ms 1524 KB Output is correct
11 Correct 3 ms 1548 KB Output is correct
12 Correct 3 ms 1592 KB Output is correct
13 Correct 4 ms 1616 KB Output is correct
14 Correct 3 ms 1640 KB Output is correct
15 Correct 3 ms 1664 KB Output is correct
16 Correct 3 ms 1688 KB Output is correct
17 Correct 4 ms 1760 KB Output is correct
18 Correct 4 ms 1760 KB Output is correct
19 Correct 4 ms 1808 KB Output is correct
20 Correct 3 ms 1832 KB Output is correct
21 Correct 3 ms 1832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 3 ms 1164 KB Output is correct
3 Correct 3 ms 1264 KB Output is correct
4 Correct 4 ms 1304 KB Output is correct
5 Correct 3 ms 1388 KB Output is correct
6 Correct 3 ms 1412 KB Output is correct
7 Correct 3 ms 1452 KB Output is correct
8 Correct 3 ms 1476 KB Output is correct
9 Correct 3 ms 1500 KB Output is correct
10 Correct 3 ms 1524 KB Output is correct
11 Correct 3 ms 1548 KB Output is correct
12 Correct 3 ms 1592 KB Output is correct
13 Correct 4 ms 1616 KB Output is correct
14 Correct 3 ms 1640 KB Output is correct
15 Correct 3 ms 1664 KB Output is correct
16 Correct 3 ms 1688 KB Output is correct
17 Correct 4 ms 1760 KB Output is correct
18 Correct 4 ms 1760 KB Output is correct
19 Correct 4 ms 1808 KB Output is correct
20 Correct 3 ms 1832 KB Output is correct
21 Correct 3 ms 1832 KB Output is correct
22 Correct 78 ms 7384 KB Output is correct
23 Correct 87 ms 9132 KB Output is correct
24 Correct 74 ms 9132 KB Output is correct
25 Correct 76 ms 9132 KB Output is correct
26 Correct 85 ms 9132 KB Output is correct
27 Correct 73 ms 9132 KB Output is correct
28 Correct 76 ms 9132 KB Output is correct
29 Correct 75 ms 9132 KB Output is correct
30 Correct 74 ms 9304 KB Output is correct
31 Correct 72 ms 9304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 12072 KB Output is correct
2 Correct 152 ms 12072 KB Output is correct
3 Correct 159 ms 12072 KB Output is correct
4 Correct 160 ms 12152 KB Output is correct
5 Correct 153 ms 12152 KB Output is correct
6 Correct 153 ms 12152 KB Output is correct
7 Correct 152 ms 12152 KB Output is correct
8 Correct 152 ms 18072 KB Output is correct
9 Correct 206 ms 23228 KB Output is correct
10 Correct 164 ms 30160 KB Output is correct
11 Correct 177 ms 34308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 3 ms 1164 KB Output is correct
3 Correct 3 ms 1264 KB Output is correct
4 Correct 4 ms 1304 KB Output is correct
5 Correct 3 ms 1388 KB Output is correct
6 Correct 3 ms 1412 KB Output is correct
7 Correct 3 ms 1452 KB Output is correct
8 Correct 3 ms 1476 KB Output is correct
9 Correct 3 ms 1500 KB Output is correct
10 Correct 3 ms 1524 KB Output is correct
11 Correct 3 ms 1548 KB Output is correct
12 Correct 3 ms 1592 KB Output is correct
13 Correct 4 ms 1616 KB Output is correct
14 Correct 3 ms 1640 KB Output is correct
15 Correct 3 ms 1664 KB Output is correct
16 Correct 3 ms 1688 KB Output is correct
17 Correct 4 ms 1760 KB Output is correct
18 Correct 4 ms 1760 KB Output is correct
19 Correct 4 ms 1808 KB Output is correct
20 Correct 3 ms 1832 KB Output is correct
21 Correct 3 ms 1832 KB Output is correct
22 Correct 78 ms 7384 KB Output is correct
23 Correct 87 ms 9132 KB Output is correct
24 Correct 74 ms 9132 KB Output is correct
25 Correct 76 ms 9132 KB Output is correct
26 Correct 85 ms 9132 KB Output is correct
27 Correct 73 ms 9132 KB Output is correct
28 Correct 76 ms 9132 KB Output is correct
29 Correct 75 ms 9132 KB Output is correct
30 Correct 74 ms 9304 KB Output is correct
31 Correct 72 ms 9304 KB Output is correct
32 Correct 176 ms 12072 KB Output is correct
33 Correct 152 ms 12072 KB Output is correct
34 Correct 159 ms 12072 KB Output is correct
35 Correct 160 ms 12152 KB Output is correct
36 Correct 153 ms 12152 KB Output is correct
37 Correct 153 ms 12152 KB Output is correct
38 Correct 152 ms 12152 KB Output is correct
39 Correct 152 ms 18072 KB Output is correct
40 Correct 206 ms 23228 KB Output is correct
41 Correct 164 ms 30160 KB Output is correct
42 Correct 177 ms 34308 KB Output is correct
43 Correct 182 ms 40400 KB Output is correct
44 Correct 182 ms 46456 KB Output is correct
45 Correct 178 ms 52572 KB Output is correct
46 Correct 160 ms 58732 KB Output is correct
47 Correct 161 ms 64784 KB Output is correct
48 Runtime error 146 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 -