QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#750593 | #9713. Kill the tree | jiangzhihui | WA | 93ms | 36688kb | C++23 | 1.7kb | 2024-11-15 15:06:59 | 2024-11-15 15:07:00 |
Judging History
answer
/*
* @Author: Bingbong
* @Date: 2024-11-15 14:50:27
* @Last Modified by: Bingbong
* @Last Modified time: 2024-11-15 15:06:48
*/
#include<bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include<bits/Bingbong.h>
#endif
using namespace std;
using i64=long long;
#define pi acos(-1)
void solve(){
int n;
cin>>n;
vector<vector<int>>e(n+1);
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
vector<int>sz(n+1,1);
vector<int>son(n+1);
vector<int>fat(n+1);
vector<vector<int>>ans(n+1);
auto dfs=[&](auto &&self,int u,int fa)->void {
fat[u]=fa;
for(auto v:e[u]){
if(v==fa) continue;
self(self,v,u);
sz[u]+=sz[v];
if(sz[son[u]]<sz[v]){
son[u]=v;
}
}
if(son[u]==0){
son[u]=u;
ans[u].push_back(u);
return ;
}
int now=ans[son[u]][0];
bool ok=false;
while(sz[now]<=sz[u]-sz[now]){
if(sz[now]==sz[u]-sz[now]){
ans[u].push_back(now);
ans[u].push_back(fat[now]);
sort(ans[u].begin(),ans[u].end());
ok=true;
break;
}
now=fat[now];
}
if(!ok) ans[u].push_back(now);
};
dfs(dfs,1,0);
for(int i=1;i<=n;i++){
sort(ans[i].begin(),ans[i].end());
for(auto t:ans[i]) cout<<t<<" ";
cout<<"\n";
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
while(t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 93ms
memory: 36688kb
input:
200000 42924 18271 60536 154257 107175 95680 196335 71607 158051 155259 110869 30974 143595 43516 4228 138046 26249 183847 123888 199873 15009 25362 166527 175160 15257 67159 124779 199363 148904 54047 5988 18123 58281 40739 44562 143880 72819 132492 137782 29662 130741 78276 55073 93292 82700 18328...
output:
1 134385 45886 143670 106649 126220 44121 108393 5226 95313 116080 147311 141180 147983 7428 74120 161963 3879 178499 162544 171549 144413 127262 133093 188325 171802 43558 28179 125217 140604 186651 45633 176397 26425 3745 26982 30063 128965 19661 148036 141733 115691 3...
result:
wrong answer 69525th numbers differ - expected: '95293', found: '20885'