QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#827370 | #9911. 路南柯 | valeriu | 0 | 4ms | 3812kb | C++20 | 1.4kb | 2024-12-22 22:12:08 | 2024-12-22 22:12:12 |
answer
//sursa copiata pentru ca idfk man
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=105;
int n,deg[N];
vector<int> G[N];
vector<vector<int> > ans;
void dfs(int u,int fa){
if(fa) G[u].erase(find(G[u].begin(),G[u].end(),fa)),G[u].insert(G[u].begin(),fa);
for(auto v:G[u]) if(v!=fa) dfs(v,u);
ans.back().pb(u);
}
void SOLVE(){
cin>>n,ans.clear();
for(int i=1;i<=n;i++) G[i].clear(),deg[i]=0;
for(int i=1,u,v;i<n;i++) cin>>u>>v,G[u].pb(v),G[v].pb(u);
if(n<3) return cout<<"0\n",void();
for(int i=1;i<=n;i++){
if((int)G[i].size()==n-1){
cout<<"2\n";
for(int j:G[i]) cout<<j<<' ';
cout<<i<<'\n',reverse(G[i].begin(),G[i].end());
for(int j:G[i]) cout<<j<<' ';
cout<<i<<'\n';
return;
}
deg[i]+=(int)G[i].size();
if((int)G[i].size()==1) --deg[G[i][0]],deg[i]=0;
sort(G[i].begin(),G[i].end(),[&](int x,int y){return G[x].size()>G[y].size();});
}
for(int i=1;i<=n;i++) if(deg[i]==1){
ans.pb({}),dfs(i,0);
if((int)ans.size()==1) for(int j=1;j<=n;j++) reverse(G[j].begin()+1,G[j].end());
}
cout<<(int)ans.size()<<'\n';
//for(auto i:ans){
//for(auto j:i) cout<<j<<' ';
//cout<<'\n';
//}
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int _;cin>>_;
while(_--) SOLVE();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3812kb
input:
10 10 4 2 5 1 8 6 1 9 3 7 1 8 10 2 6 4 3 4 10 4 3 3 1 5 3 6 3 2 3 8 7 8 2 7 10 8 9 10 5 4 10 8 10 3 6 3 9 8 1 10 4 2 2 7 8 4 10 10 6 6 8 1 7 2 6 3 5 3 9 4 2 6 9 3 1 10 2 8 10 4 9 1 9 3 5 7 6 3 1 8 8 7 4 2 10 9 2 9 1 7 1 5 6 8 2 3 9 5 10 5 4 1 10 10 2 9 8 1 8 5 6 3 7 1 6 2 9 8 2 10 4 2 10 5 7 6 2 8 7...
output:
3 2 2 2 3 2 2 2 2 2
result:
wrong output format Unexpected end of file - int32 expected
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 4ms
memory: 3628kb
input:
100 100 90 19 79 98 23 34 50 41 31 52 61 19 50 30 49 5 95 65 22 44 72 89 49 77 27 7 48 2 28 25 56 12 97 63 98 43 10 4 50 33 12 13 54 16 100 43 23 69 53 5 56 85 39 6 64 92 100 59 2 71 44 29 59 97 64 39 75 53 59 89 16 35 67 16 6 43 38 51 36 22 58 70 3 29 9 61 99 11 49 95 27 72 73 89 23 3 14 3 61 57 26...
output:
15 20 15 15 15 17 19 18 19 18 16 17 15 16 14 19 13 17 16 18 17 17 16 20 15 17 17 18 16 17 15 15 17 16 17 15 14 22 17 18 15 19 19 20 16 20 15 18 14 19 18 17 18 16 19 16 17 19 15 18 15 17 16 17 19 14 12 14 14 20 12 17 17 17 17 15 17 19 21 17 15 14 18 17 14 19 17 15 17 17 20 17 18 16 20 18 18 13 20 21
result:
wrong output format Unexpected end of file - int32 expected