QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#827783 | #9911. 路南柯 | Hanghang | 69.337083 | 18ms | 3616kb | C++20 | 1.2kb | 2024-12-23 09:57:03 | 2024-12-23 09:57:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=103;
int n,m,tim=0,fa[N],sz[N],leaf[N],a[N][N];
bool ban[N],nb[N];
vector<int>ve[N];
void Dfs(int x){for(int y:ve[x])if(y!=fa[x])fa[y]=x,Dfs(y);}
bool Cmp(int x,int y)
{
bool fx=ve[x].size()==1,fy=ve[y].size()==1;
return fx!=fy?fx>fy:nb[x]<nb[y];
}
void Ans(int x,int Fa)
{
a[m][++tim]=x;sort(ve[x].begin(),ve[x].end(),Cmp);
for(int y:ve[x])if(y!=Fa)Ans(y,x);
}
void Solve()
{
cin>>n;m=0;
for(int i=1;i<=n;i++)ve[i].clear(),sz[i]=leaf[i]=ban[i]=nb[i]=0;
for(int i=1,x,y;i<n;i++)cin>>x>>y,ve[x].push_back(y),ve[y].push_back(x);
Dfs(1);
for(int x=1;x<=n;x++)if(ve[x].size()==1)for(int y:ve[x])leaf[y]++;
for(int x=1;x<=n;x++)if(ve[x].size()==1&&!ban[x])
{
nb[x]=1;
for(int y:ve[x])
{
sz[y]++;m++;tim=0;a[m][++tim]=x;Ans(y,x);
for(int z:ve[x])if(z!=y)Ans(z,x);
}
for(int y:ve[x])if(sz[y]+1==leaf[y])for(int z:ve[y])if(ve[z].size()==1)ban[z]=1;
}
cout<<m<<endl;
for(int t=1;t<=m;t++,cout<<endl)for(int i=n;i;i--)cout<<a[t][i]<<" ";
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T;cin>>T;
while(T--)Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 19.0579
Acceptable Answer
Test #1:
score: 19.0579
Acceptable Answer
time: 1ms
memory: 3588kb
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 7 3 10 2 4 6 8 9 1 5 5 9 1 8 6 10 2 4 3 7 7 3 5 9 1 8 6 4 2 10 5 10 7 9 8 2 6 5 4 3 1 10 7 9 8 2 1 6 5 3 4 10 7 9 8 2 1 4 6 3 5 1 4 5 6 3 2 10 7 8 9 1 4 5 6 3 2 9 8 7 10 5 6 3 7 2 5 4 9 8 10 1 6 3 1 10 9 8 7 2 4 5 7 2 5 4 9 8 1 10 3 6 6 3 1 10 9 8 5 4 2 7 7 2 5 4 6 3 1 10 8 9 4 7 1 5 ...
result:
points 0.9528946 Partial correct.
Subtask #2:
score: 50.2792
Acceptable Answer
Test #2:
score: 50.2792
Acceptable Answer
time: 18ms
memory: 3616kb
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:
33 8 58 70 81 21 80 87 15 82 57 9 61 19 90 62 63 97 31 52 71 2 48 54 78 67 16 35 93 20 26 91 76 88 40 37 84 92 64 66 39 24 6 47 45 79 98 43 100 59 7 27 72 89 42 73 69 60 34 23 14 3 10 4 75 53 51 38 65 95 94 28 25 77 49 5 17 36 22 68 44 29 33 41 50 83 30 86 46 55 99 18 11 32 74 96 85 56 12 13 1 80 8...
result:
points 0.6284898936 Partial correct.