답안 #75857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
75857 2018-09-11T11:12:00 Z chunghan 트리 (KOI16_tree) C++14
36 / 100
2000 ms 66560 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>

using namespace std;

int n, q, par[200001], set[200001], b, c, d;
vector<int> chi[200001];

void r(int p, int c) {
    int i;
    for(i = 0; i < chi[p].size(); i++)
        if(chi[p][i] == c) break;
    if(i < chi[p].size()) chi[p].erase(chi[p].begin() + i);
}

void f(int a, int p) {
    set[a] = p;
    for(int i = 0; i < chi[a].size(); i++) {
        f(chi[a][i], p);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> q;
    set[1] = 1;
    for(int i = 2; i <= n; i++) {
        cin >> par[i];
        chi[par[i]].push_back(i);
        set[i] = 1;
    }
    for(int i = 0; i < q; i++) {
        cin >> b >> c >> d;
        if(set[b] == set[c]) {
            cout << "YES" << endl;
            if(d) {
                r(par[b], b);
                f(b, b);
            }
        } else {
            cout << "NO" << endl;
            if(d) {
                r(par[c], c);
                f(c, c);
            }
        }
    }
    return 0;
}

Compilation message

tree.cpp: In function 'void r(int, int)':
tree.cpp:13:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i = 0; i < chi[p].size(); i++)
                ~~^~~~~~~~~~~~~~~
tree.cpp:15:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(i < chi[p].size()) chi[p].erase(chi[p].begin() + i);
        ~~^~~~~~~~~~~~~~~
tree.cpp: In function 'void f(int, int)':
tree.cpp:20:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < chi[a].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 5304 KB Output is correct
2 Correct 9 ms 5304 KB Output is correct
3 Correct 8 ms 5444 KB Output is correct
4 Correct 8 ms 5452 KB Output is correct
5 Correct 8 ms 5500 KB Output is correct
6 Correct 9 ms 5716 KB Output is correct
7 Correct 11 ms 5716 KB Output is correct
8 Correct 10 ms 5784 KB Output is correct
9 Correct 8 ms 5784 KB Output is correct
10 Correct 8 ms 5784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 5304 KB Output is correct
2 Correct 9 ms 5304 KB Output is correct
3 Correct 8 ms 5444 KB Output is correct
4 Correct 8 ms 5452 KB Output is correct
5 Correct 8 ms 5500 KB Output is correct
6 Correct 9 ms 5716 KB Output is correct
7 Correct 11 ms 5716 KB Output is correct
8 Correct 10 ms 5784 KB Output is correct
9 Correct 8 ms 5784 KB Output is correct
10 Correct 8 ms 5784 KB Output is correct
11 Correct 8 ms 5784 KB Output is correct
12 Correct 8 ms 5852 KB Output is correct
13 Correct 8 ms 5868 KB Output is correct
14 Correct 9 ms 5884 KB Output is correct
15 Correct 8 ms 5904 KB Output is correct
16 Correct 8 ms 5916 KB Output is correct
17 Correct 9 ms 6060 KB Output is correct
18 Correct 8 ms 6060 KB Output is correct
19 Correct 8 ms 6060 KB Output is correct
20 Correct 8 ms 6060 KB Output is correct
21 Correct 8 ms 6060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 5304 KB Output is correct
2 Correct 9 ms 5304 KB Output is correct
3 Correct 8 ms 5444 KB Output is correct
4 Correct 8 ms 5452 KB Output is correct
5 Correct 8 ms 5500 KB Output is correct
6 Correct 9 ms 5716 KB Output is correct
7 Correct 11 ms 5716 KB Output is correct
8 Correct 10 ms 5784 KB Output is correct
9 Correct 8 ms 5784 KB Output is correct
10 Correct 8 ms 5784 KB Output is correct
11 Correct 8 ms 5784 KB Output is correct
12 Correct 8 ms 5852 KB Output is correct
13 Correct 8 ms 5868 KB Output is correct
14 Correct 9 ms 5884 KB Output is correct
15 Correct 8 ms 5904 KB Output is correct
16 Correct 8 ms 5916 KB Output is correct
17 Correct 9 ms 6060 KB Output is correct
18 Correct 8 ms 6060 KB Output is correct
19 Correct 8 ms 6060 KB Output is correct
20 Correct 8 ms 6060 KB Output is correct
21 Correct 8 ms 6060 KB Output is correct
22 Correct 396 ms 9000 KB Output is correct
23 Correct 400 ms 11088 KB Output is correct
24 Correct 394 ms 13288 KB Output is correct
25 Correct 383 ms 15616 KB Output is correct
26 Correct 398 ms 17760 KB Output is correct
27 Correct 389 ms 20072 KB Output is correct
28 Correct 385 ms 22164 KB Output is correct
29 Correct 396 ms 24560 KB Output is correct
30 Correct 384 ms 26780 KB Output is correct
31 Correct 389 ms 29024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 5304 KB Output is correct
2 Correct 9 ms 5304 KB Output is correct
3 Correct 8 ms 5444 KB Output is correct
4 Correct 8 ms 5452 KB Output is correct
5 Correct 8 ms 5500 KB Output is correct
6 Correct 9 ms 5716 KB Output is correct
7 Correct 11 ms 5716 KB Output is correct
8 Correct 10 ms 5784 KB Output is correct
9 Correct 8 ms 5784 KB Output is correct
10 Correct 8 ms 5784 KB Output is correct
11 Correct 1035 ms 45336 KB Output is correct
12 Correct 1078 ms 51192 KB Output is correct
13 Correct 938 ms 53676 KB Output is correct
14 Correct 914 ms 58176 KB Output is correct
15 Correct 955 ms 61240 KB Output is correct
16 Correct 902 ms 64776 KB Output is correct
17 Execution timed out 2073 ms 66560 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 5304 KB Output is correct
2 Correct 9 ms 5304 KB Output is correct
3 Correct 8 ms 5444 KB Output is correct
4 Correct 8 ms 5452 KB Output is correct
5 Correct 8 ms 5500 KB Output is correct
6 Correct 9 ms 5716 KB Output is correct
7 Correct 11 ms 5716 KB Output is correct
8 Correct 10 ms 5784 KB Output is correct
9 Correct 8 ms 5784 KB Output is correct
10 Correct 8 ms 5784 KB Output is correct
11 Correct 8 ms 5784 KB Output is correct
12 Correct 8 ms 5852 KB Output is correct
13 Correct 8 ms 5868 KB Output is correct
14 Correct 9 ms 5884 KB Output is correct
15 Correct 8 ms 5904 KB Output is correct
16 Correct 8 ms 5916 KB Output is correct
17 Correct 9 ms 6060 KB Output is correct
18 Correct 8 ms 6060 KB Output is correct
19 Correct 8 ms 6060 KB Output is correct
20 Correct 8 ms 6060 KB Output is correct
21 Correct 8 ms 6060 KB Output is correct
22 Correct 396 ms 9000 KB Output is correct
23 Correct 400 ms 11088 KB Output is correct
24 Correct 394 ms 13288 KB Output is correct
25 Correct 383 ms 15616 KB Output is correct
26 Correct 398 ms 17760 KB Output is correct
27 Correct 389 ms 20072 KB Output is correct
28 Correct 385 ms 22164 KB Output is correct
29 Correct 396 ms 24560 KB Output is correct
30 Correct 384 ms 26780 KB Output is correct
31 Correct 389 ms 29024 KB Output is correct
32 Correct 1035 ms 45336 KB Output is correct
33 Correct 1078 ms 51192 KB Output is correct
34 Correct 938 ms 53676 KB Output is correct
35 Correct 914 ms 58176 KB Output is correct
36 Correct 955 ms 61240 KB Output is correct
37 Correct 902 ms 64776 KB Output is correct
38 Execution timed out 2073 ms 66560 KB Time limit exceeded
39 Halted 0 ms 0 KB -