QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#253435 | #5088. Two Choreographies | NYCU_gAwr_gurA | WA | 37ms | 13868kb | C++20 | 1.5kb | 2023-11-17 00:03:35 | 2023-11-17 00:03:36 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define matsuri pair<int,int>
const int iris = 1e9+7;
//const int iris = 998244353;
using namespace std;
int cc=2;
vector<int> G[100001],path;
int dis[100001], v[100001];
int cnt[100001];
int dfs1(int a,int f,int d)
{
v[a]=1;
dis[a]=d;
path.emplace_back(a);
for(int b:G[a])
{
if(b==f)
continue;
if(dis[b])
{
int cy=d-dis[b]+1;
if(!cnt[cy])
cnt[cy]=1;
else
{
dis[a]=0;
path.pop_back();
return cy;
}
}
else
{
int cy=dfs1(b,a,d+1);
if(cy)
{
dis[a]=0;
path.pop_back();
return cy;
}
}
}
path.pop_back();
dis[a]=0;
return 0;
}
void dfs2(int a,int f,int d,int k)
{
if(!cc)
return;
v[a]=2;
dis[a]=d;
path.emplace_back(a);
for(int b:G[a])
{
if(b==f)
continue;
if(dis[b])
{
int cy=d-dis[b]+1;
if(cy==k)
{
int i=path.size();
while(1)
{
i--;
cout<<path[i]<<' ';
if(path[i]==b)
break;
}
cout<<'\n';
cc--;
}
}
else
dfs2(b,a,d+1,k);
}
path.pop_back();
dis[a]=0;
return;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
for(int i=0;i<n*2-3;i++)
{
int a,b;
cin>>a>>b;
G[a].emplace_back(b);
G[b].emplace_back(a);
}
int k=-1;
for(int i=1;i<=n;i++)
{
if(v[i]<1)
{
k=dfs1(i,0,1);
if(k!=-1)
break;
}
}
cout<<k<<'\n';
for(int i=1;i<=n;i++)
{
if(v[i]<2)
dfs2(i,0,1,k);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6476kb
input:
4 1 2 1 3 1 4 2 3 2 4
output:
3 3 2 1 4 2 1
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 6220kb
input:
5 1 2 1 3 1 4 1 5 2 3 2 5 3 4
output:
3 3 2 1 5 2 1
result:
ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 6260kb
input:
7 1 2 3 4 5 6 5 2 3 1 6 1 4 2 4 5 2 6 3 6 1 5
output:
4 6 5 2 1 4 3 6 5
result:
ok
Test #4:
score: 0
Accepted
time: 1ms
memory: 6628kb
input:
40 1 16 1 40 2 4 2 16 2 36 3 25 3 38 4 1 4 13 5 11 5 27 6 4 7 5 7 11 8 10 8 14 8 24 9 34 10 20 12 35 13 2 14 10 14 20 15 18 15 28 15 31 16 6 16 13 17 5 17 11 17 27 18 9 19 1 19 4 19 16 20 24 21 12 21 33 21 35 22 38 23 12 23 21 25 28 25 31 25 34 25 38 26 14 26 20 27 7 27 11 28 3 28 31 29 16 29 19 30 ...
output:
4 4 2 16 1 13 4 2 16
result:
ok
Test #5:
score: 0
Accepted
time: 0ms
memory: 6392kb
input:
201 1 7 1 114 1 119 2 49 2 93 4 197 5 139 6 1 6 27 7 39 7 121 8 127 9 130 9 145 11 106 11 136 11 193 12 2 12 116 13 55 13 69 13 105 13 187 13 196 14 144 14 177 15 127 15 134 15 145 15 155 15 184 15 199 16 96 16 177 17 20 21 100 22 68 22 71 22 81 22 142 23 148 23 190 24 12 24 81 24 89 25 158 25 159 2...
output:
16 158 25 35 163 176 119 109 48 50 82 95 97 153 31 34 39 164 6 27 73 158 25 35 163 176 119 109 48 50 82 95 97
result:
ok
Test #6:
score: 0
Accepted
time: 3ms
memory: 7032kb
input:
8000 2 1508 2 3068 3 5268 3 5501 6 266 6 2737 6 3197 6 5863 6 6697 7 3492 9 427 9 794 9 3114 9 5509 10 2257 10 4348 11 1479 11 1957 11 2230 11 2500 11 3182 11 4399 11 5051 11 7727 12 7669 13 1403 13 5753 14 2871 14 6956 14 7959 15 6902 17 1630 17 3155 17 5950 18 7232 19 125 19 3280 19 5648 20 6879 2...
output:
110 1967 5436 293 1067 49 1873 2505 997 5138 1558 2978 3143 2760 2118 1004 2114 4559 524 2479 2963 1990 1455 1644 2148 396 1134 5383 557 3302 986 1875 1900 4697 1055 822 245 348 1264 3083 3449 2653 4430 1772 6089 2637 5394 871 1002 335 5258 521 1149 3605 5951 984 2328 3738 3688 539 713 461 4233 209 ...
result:
ok
Test #7:
score: 0
Accepted
time: 30ms
memory: 13744kb
input:
99999 1 11261 1 21544 2 9017 2 63063 2 97990 3 11995 3 42473 4 19846 5 38099 6 35872 6 80509 7 73231 8 12356 9 35384 10 45091 12 86727 13 4938 13 48917 14 62383 14 89846 15 28458 15 44277 15 51725 15 84522 16 93258 17 13934 17 42238 18 19000 19 11278 19 23672 19 61502 19 78791 20 85057 20 88080 21 2...
output:
472 15118 11478 61678 33467 38027 5104 8918 9428 4610 20759 46945 50796 3246 41970 3025 41042 3261 57799 35078 28756 24841 19566 19997 1946 8072 56757 15817 26556 10610 17735 24780 11961 99211 26319 35581 25888 81579 49523 50704 90032 43313 69536 26429 1693 64917 8737 13175 63526 47017 7049 8731 146...
result:
ok
Test #8:
score: 0
Accepted
time: 37ms
memory: 13868kb
input:
100000 1 68531 2 97359 4 68578 4 83098 4 98443 5 8053 5 30270 5 86617 6 7074 6 12266 6 69396 7 52675 7 78316 7 90757 7 92242 8 32677 8 41353 8 41457 8 74508 9 44234 10 4973 10 38390 10 96049 11 28007 11 68620 13 3016 14 36748 15 8147 15 25110 15 28489 15 72947 15 99347 16 70760 17 12774 17 68407 17 ...
output:
1165 63500 4304 23188 21746 83928 12397 15223 33344 4391 23476 12399 17224 39983 357 2387 91759 45792 64636 12719 50491 81210 21625 14143 19154 3080 81611 32442 33153 36657 14836 2812 67623 6017 43303 65078 34138 79009 42634 5096 65928 45332 11463 6742 70849 67930 51540 62864 92010 97187 24475 93498...
result:
ok
Test #9:
score: -100
Wrong Answer
time: 1ms
memory: 7632kb
input:
7 1 2 2 3 3 4 4 5 5 6 6 7 7 5 1 4 7 3 1 6 7 1
output:
3 7 6 5 6 7 5
result:
wrong answer Wrong output - Identical cycle.