Submission #75857

#TimeUsernameProblemLanguageResultExecution timeMemory
75857chunghan트리 (KOI16_tree)C++14
36 / 100
2073 ms66560 KiB
#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 (stderr)

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++) {
                    ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...