QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#412918 | #6745. Delete the Tree | Savior | WA | 0ms | 3676kb | C++20 | 1.3kb | 2024-05-16 21:37:10 | 2024-05-16 21:37:11 |
Judging History
answer
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
#define int long long
using ll = long long;
const int inf = 1e17+7;
const int N=505;
const int mod =1e9+7;
typedef pair<int,int>P;
int mn=inf,rt=0,n=0;
int tot=0;
int sz[N];
vector<int>ans[N];
int vis[N];
vector<int>e[N];
void get(int u,int fa){
sz[u]=1;
int mx=0;
for(auto v:e[u]){
if(v==fa||vis[v]) continue;
get(v,u);
mx=max(mx,sz[v]);
sz[u]+=sz[v];
}
mx=max(mx,n-sz[u]);
if(mx<mn) mn=mx,rt=u;
return;
}
void dfs(int u,int fa,int w){
if(vis[u]) return;
ans[w].push_back(u);
tot=max(tot,w);
vis[u]=1;
for(auto v:e[u]){
if(v==fa||vis[v]) continue;
mn=inf,n=sz[v];
get(v,u);
dfs(rt,0,w+1);
}
}
void solve(){
cin>>n;
for(int i=1;i<n;i++){
int u,v;
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
get(1,0);
dfs(rt,0,0);
cout<<tot+1<<endl;
for(int i=0;i<=tot;i++){
cout<<ans[i].size()<<' ';
for(auto&it:ans[i])
cout<<it<<' ';
cout<<endl;
}
return;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int t=1;//cin>>t;
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3676kb
input:
5 1 2 1 3 1 4 4 5
output:
3 1 1 3 2 3 5 1 4
result:
wrong answer