QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#721301 | #9713. Kill the tree | OOBMABTRAMS# | WA | 70ms | 36640kb | C++17 | 843b | 2024-11-07 15:47:41 | 2024-11-07 15:47:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=500013;
vector<int>mp[N];
int sz[N],ans[N],p[N];
int ans2[N];
void dfs(int x,int fa) {
sz[x]=1;ans[x]=x;p[x]=fa;
for(auto i:mp[x]) if(i^fa){
dfs(i,x);
sz[x]+=sz[i];
}
int son=0;
for(auto i:mp[x])if(i^fa)if(sz[i]*2>=sz[x])son=i;
if(son) {
ans[x]=ans[son];
while(sz[ans[x]]*2<sz[x])ans[x]=p[ans[x]];
}
if(ans[x]!=x) {
if(sz[ans[x]]*2==sz[x])ans2[x]=p[ans[x]];
}
}
signed main(){
ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=1,x,y;i<n;i++) cin>>x>>y,mp[x].push_back(y),mp[y].push_back(x);
dfs(1,0);
for(int i=1;i<=n;i++) {
cout<<ans[i];
if(ans2[i])cout<<' '<<ans2[i]<<'\n';
else cout<<'\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 70ms
memory: 36640kb
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:
134385 1 143670 45886 126220 106649 108393 44121 95313 5226 116080 147311 141180 147983 7428 74120 161963 3879 178499 162544 171549 144413 127262 188325 133093 171802 43558 28179 125217 140604 186651 176397 45633 26425 26982 3745 30063 128965 148036 19661 141733 115691 3491 8560 36057 195673 12536 1...
result:
wrong answer 1st numbers differ - expected: '1', found: '134385'