QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#778251 | #9713. Kill the tree | surenjamts# | WA | 255ms | 42684kb | C++20 | 1.9kb | 2024-11-24 13:38:26 | 2024-11-24 13:38:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> adj[200005];
int sz[200005];
int c[200005];
vector<int> ans[200005];
int mn[200005];
void dfs(int node, int pre){
sz[node]=1;
int sum = 0;
for(int i: adj[node]){
if(i!=pre){
dfs(i,node);
sz[node]+=sz[i];
}
}
}
void dfs2(int node, int pre, int dep){
c[1]+=dep;
for(int i: adj[node]){
if(i!=pre){
dfs2(i,node,dep+1);
}
}
}
void dfs3(int node, int pre){
int mno=c[node];
mn[node]=c[node];
ans[node].push_back(node);
for(int i: adj[node]){
if(i!=pre){
dfs3(i,node);
if(mn[i]<mn[node]){
//mno=c[i];
mn[node]=mn[i];
ans[node].clear();
for(int j: ans[i]){
ans[node].push_back(j);
}
}
else if(mn[i]==mn[node]){
for(int j: ans[i]){
ans[node].push_back(j);
}
}
else{
}
}
}
}
void dfs4(int node, int pre){
for(int i: adj[node]){
if(i!=pre){
c[i] = c[node] + sz[1] - sz[i] * 2;
dfs4(i,node);
}
}
}
void solve(){
int n;
cin>>n;
for(int i=0; i<n-1; i++){
int u,v;
cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1,0);
dfs2(1,0,0);
dfs4(1,0);
// for(int i=1; i<=n; i++){
//// cout<<c[i]<<" ";
// }
// cout<<endl;
dfs3(1,0);
for(int i=1; i<=n; i++){
sort(ans[i].begin(),ans[i].end());
for(int j: ans[i]){
cout<<j<<" ";
}
cout<<'\n';
}
}
signed main(){
int t=1;
//cin>>t;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 255ms
memory: 42684kb
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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76...
result:
wrong answer 3rd numbers differ - expected: '45886', found: '2'