# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
365644 | kshitij_sodani | Min-max tree (BOI18_minmaxtree) | C++14 | 180 ms | 27372 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |