QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#822615 | #9911. 路南柯 | zjy0001 | 2 | 9ms | 3636kb | C++17 | 1.4kb | 2024-12-20 14:54:30 | 2024-12-20 14:54:30 |
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long long
using namespace std;
const int N=105;
int n;
int deg[N];
vector<int>G[N];
vector<vector<int>>ans;
inline void dfs(int u,int fa){
for(auto v:G[u])if(v!=fa)dfs(v,u);
ans.back().emplace_back(u);
}
inline void MAIN(){
cin>>n,ans.clear();
for(int i=1;i<=n;++i)G[i].clear();
for(int i=1;i<n;++i){
int u,v;cin>>u>>v;
G[u].emplace_back(v);
G[v].emplace_back(u);
}
if(n<3)return cout<<"0\n",void();
for(int i=1;i<=n;++i)
if(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;
}
else deg[i]=G[i].size();
for(int i=1;i<=n;++i)if(G[i].size()==1)--deg[G[i][0]],deg[i]=0;
for(int i=1;i<=n;++i)if(deg[i]==1){
ans.emplace_back(),dfs(i,0);
if(ans.size()==1)for(int j=1;j<=n;++j)reverse(G[j].begin(),G[j].end());
}
cout<<ans.size()<<'\n';
for(auto vec:ans){
for(int i:vec)cout<<i<<' ';
cout<<'\n';
}
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
int t=1;cin>>t;while(t--)MAIN();
return 0;
}
/*
2
5
2 3
3 1
5 1
5 4
5
1 4
2 3
3 1
5 3
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 2
Acceptable Answer
Test #1:
score: 2
Acceptable Answer
time: 0ms
memory: 3608kb
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 5 9 10 2 7 3 4 6 8 1 10 7 3 9 5 1 8 6 4 2 9 5 1 8 6 10 2 4 7 3 2 4 1 5 6 10 7 9 8 2 3 10 9 6 5 1 4 3 2 8 7 2 5 6 3 1 10 9 8 4 7 2 6 1 7 2 5 4 9 8 10 3 2 7 5 10 8 4 2 6 9 3 1 4 7 1 5 3 9 8 10 6 2 3 10 4 2 5 7 8 1 9 6 3 5 7 6 3 9 1 8 2 10 4 6 3 9 1 10 4 2 8 5 7 2 7 6 4 5 10 1 3 9 8 2 4 ...
result:
points 0.1 Partial correct.
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 9ms
memory: 3636kb
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 10 94 28 25 77 65 51 38 95 49 34 7 27 72 79 47 45 98 92 40 76 91 88 37 84 20 26 64 66 39 24 71 31 52 2 48 54 67 78 16 35 93 6 43 100 63 62 97 59 89 9 82 57 61 19 90 42 73 69 80 87 15 60 23 14 81 21 3 41 58 8 70 86 18 1 13 12 85 56 96 74 32 11 99 55 46 83 30 50 33 29 68 44 17 36 22 5 53 75 4 1 18...
result:
points 0.0 Partial correct.