# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
365644 | 2021-02-12T05:14:04 Z | kshitij_sodani | Min-max tree (BOI18_minmaxtree) | C++14 | 180 ms | 27372 KB |
//#pragma GCC optimize("Ofast,unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long llo; #define mp make_pair #define pb push_back #define a first #define b second #define endl '\n' llo n,k; vector<llo> pre[100001]; set<llo> cur[100001]; vector<llo> adj[100001]; llo dfs(llo no,llo par=-1){ llo ma=-1; llo ind=-1; vector<llo> ss; for(auto j:adj[no]){ if(j!=par){ llo x=dfs(j,no); ss.pb(x); //cout<<no<<":"<<j<<":"<<x<<endl; if((llo)cur[x].size()>ma){ ma=cur[x].size(); ind=x; } } } if(ma==-1){ //cout<<no<<":"<<endl; ind=no; } for(auto j:ss){ if(j!=ind){ for(auto j:cur[j]){ if(cur[ind].find(j)!=cur[ind].end()){ cur[ind].erase(j); continue; } cur[ind].insert(j); } cur[j].clear(); } } for(auto j:pre[no]){ if(cur[ind].find(j)!=cur[ind].end()){ cur[ind].erase(j); continue; } cur[ind].insert(j); } if(par!=-1){ cout<<no+1<<" "<<par+1<<" "; if(cur[ind].size()){ cout<<(*(cur[ind].begin()))<<endl; } else{ cout<<1<<endl; } } return ind; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; for(llo i=0;i<n-1;i++){ llo aa,bb,cc; cin>>aa>>bb; aa--; bb--; adj[aa].pb(bb); adj[bb].pb(aa); } cin>>k; for(llo i=0;i<k;i++){ char s; cin>>s; llo aa,bb,cc; cin>>aa>>bb>>cc; aa--; bb--; pre[aa].pb(cc); pre[bb].pb(cc); } dfs(0); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 9708 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 151 ms | 25452 KB | Output is correct |
2 | Correct | 161 ms | 19820 KB | Output is correct |
3 | Correct | 157 ms | 26348 KB | Output is correct |
4 | Correct | 155 ms | 27372 KB | Output is correct |
5 | Correct | 180 ms | 23916 KB | Output is correct |
6 | Correct | 138 ms | 20188 KB | Output is correct |
7 | Correct | 128 ms | 18668 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 94 ms | 16492 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 9708 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |