QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#750633#9713. Kill the treejiangzhihuiWA 86ms36860kbC++231.7kb2024-11-15 15:15:582024-11-15 15:15:59

Judging History

你现在查看的是最新测评结果

  • [2024-11-15 15:15:59]
  • 评测
  • 测评结果:WA
  • 用时:86ms
  • 内存:36860kb
  • [2024-11-15 15:15:58]
  • 提交

answer

/*
 * @Author: Bingbong 
 * @Date: 2024-11-15 14:50:27 
 * @Last Modified by: Bingbong
 * @Last Modified time: 2024-11-15 15:15:33
 */

#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);
    sz[0]=0;
    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=son[u];
        //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++){
        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;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 86ms
memory: 36860kb

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 
60759 
99863 
49002 
138015 
25003 
165696 
186703 
130650 
7174 
175032 
67355 
104192 
172025 
100735 
182535 
157315 
193986 
160751 
199389 
85191 
34383 
44162 
154937 
162808 
71219 
123933 
137061 
38317 
72157 
147356 
43333 
161 
65812 
18955 
64805 
88097 
12929 
58356 
145373 
1...

result:

wrong answer 3rd numbers differ - expected: '45886', found: '60759'