QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#697812#5088. Two ChoreographiesAMATSUKAZE#WA 68ms33952kbC++202.5kb2024-11-01 15:52:542024-11-01 15:52:55

Judging History

你现在查看的是最新测评结果

  • [2024-11-01 15:52:55]
  • 评测
  • 测评结果:WA
  • 用时:68ms
  • 内存:33952kb
  • [2024-11-01 15:52:54]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define all(v) begin(v),end(v)
using namespace std;
using ll = long long;
using vl=vector<ll>;
using vvl=vector<vl>;
using vvvl=vector<vvl>;
using pll=pair<ll,ll>;
using vp=vector<pll>;
bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; }
constexpr ll INF=1LL<<60;

int main(){
    cin.tie(0)->sync_with_stdio(0);

    ll n;
    cin>>n;
    vvl g(n);
    rep(i,0,2*n-3){
        ll u,v;
        cin>>u>>v;
        u--,v--;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    vl d(n,-1);
    vl par(n,-1);
    vp ed;
    auto f=[&](auto sf,ll v,ll p)->void
    {
        par[v]=p;
        if(p>=0) d[v]=d[p]+1;
        for(auto u:g[v]){
            if(d[u]<0) sf(sf,u,v);
            else if(u!=par[v]&&d[u]<d[v]) ed.emplace_back(u,v);
        }
    };
    rep(i,0,n)if(d[i]<0) f(f,i,-1);
    vector<vp> a(n);
    for(auto [u,v]:ed){
        ll t=d[v]-d[u];
        a[t].emplace_back(u,v);
    }
    auto path=[&](pll p){
        auto [u,v]=p;
        assert(d[u]<d[v]);
        vl rs;
        while(1){
            assert(v>=0);
            rs.emplace_back(v);
            if(v==u) break;
            v=par[v];
        }
        return rs;
    };
    vvl rs(2);
    rep(i,2,n)if(a[i].size()>=2){
        rep(j,0,2) rs[j]=path(a[i][j]);
        break;
    }
    if(rs[0].empty()){
        ll m=n-2;
        assert(*max_element(all(d))==n-1);
        assert((ll)ed.size()==m);
        sort(all(ed));
        rep(i,0,m-1)if(ed[i].first==ed[i+1].first){
            auto [u,v]=ed[i];
            auto [x,y]=ed[i+1];
            if(d[v]>d[y]) swap(v,y);
            ll len=d[y]-d[v]+1;
            rs[0]=path(a[len][0]);
            rs[1]=path(pll(v,y));
            rs[1].emplace_back(u);
            break;
        }
        sort(all(ed),[](pll p,pll q){return p.second<q.second;});
        rep(i,0,m-1)if(ed[i].second==ed[i+1].second){
            auto [u,v]=ed[i];
            auto [x,y]=ed[i+1];
            if(d[u]>d[x]) swap(u,x);
            ll len=d[x]-d[u]+1;
            rs[0]=path(a[len][0]);
            rs[1]=path(pll(u,x));
            rs[1].emplace_back(v);
            break;
        }
    }
    ll sz=rs[0].size();
    cout<<sz<<endl;
    rep(i,0,sz) cout<<rs[0][i]+1<<" \n"[i==sz-1];
    rep(i,0,sz) cout<<rs[1][i]+1<<" \n"[i==sz-1];
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

4
1 2
1 3
1 4
2 3
2 4

output:

3
3 1 2
4 1 2

result:

ok 

Test #2:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

5
1 2
1 3
1 4
1 5
2 3
2 5
3 4

output:

3
3 1 2
4 3 1

result:

ok 

Test #3:

score: 0
Accepted
time: 0ms
memory: 3684kb

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
4 3 1 2
6 5 4 3

result:

ok 

Test #4:

score: 0
Accepted
time: 0ms
memory: 3600kb

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:

3
40 1 16
13 2 4

result:

ok 

Test #5:

score: 0
Accepted
time: 1ms
memory: 3684kb

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:

3
193 136 11
142 68 22

result:

ok 

Test #6:

score: 0
Accepted
time: 0ms
memory: 4760kb

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:

3
3923 3439 3738
6110 820 2842

result:

ok 

Test #7:

score: 0
Accepted
time: 59ms
memory: 21396kb

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:

3
21402 11345 61519
67758 60118 58209

result:

ok 

Test #8:

score: 0
Accepted
time: 68ms
memory: 21320kb

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:

3
23991 26684 27229
48423 3475 97816

result:

ok 

Test #9:

score: 0
Accepted
time: 0ms
memory: 3884kb

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:

4
3 4 1 2
7 3 4 1

result:

ok 

Test #10:

score: 0
Accepted
time: 27ms
memory: 33260kb

input:

100000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 5...

output:

3
3 1 2
4 3 1

result:

ok 

Test #11:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 6
1 4
8 4
8 3
8 2
1 8

output:

3
6 7 8
8 3 4

result:

ok 

Test #12:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
1 3
1 4
9 5
9 4
1 7
9 2
1 9

output:

3
3 1 2
4 3 1

result:

ok 

Test #13:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 8
1 4
10 6
1 6
10 4
10 3
1 9
10 1

output:

3
8 9 10
10 3 4

result:

ok 

Test #14:

score: 0
Accepted
time: 1ms
memory: 3948kb

input:

1000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

3
3 1 2
4 3 1

result:

ok 

Test #15:

score: 0
Accepted
time: 0ms
memory: 6308kb

input:

9999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

3
9997 9998 9999
9999 4 5

result:

ok 

Test #16:

score: 0
Accepted
time: 5ms
memory: 6304kb

input:

10000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

5
10000 9999 9998 9997 9996
7 6 5 4 1

result:

ok 

Test #17:

score: 0
Accepted
time: 39ms
memory: 31604kb

input:

94753
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
3 1 2
4 3 1

result:

ok 

Test #18:

score: 0
Accepted
time: 27ms
memory: 33268kb

input:

99999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

5
99999 99998 99997 99996 99995
6 5 4 3 1

result:

ok 

Test #19:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

7
1 2
2 3
3 4
4 5
5 6
6 7
1 3
1 4
1 5
1 6
1 7

output:

3
3 1 2
4 3 1

result:

ok 

Test #20:

score: 0
Accepted
time: 36ms
memory: 33876kb

input:

100000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 5...

output:

3
3 1 2
4 3 1

result:

ok 

Test #21:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
1 3
1 4
1 5
1 6
1 7
1 8

output:

3
3 1 2
4 3 1

result:

ok 

Test #22:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
1 3
1 4
1 5
1 6
1 7
1 8
1 9

output:

3
3 1 2
4 3 1

result:

ok 

Test #23:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10

output:

3
3 1 2
4 3 1

result:

ok 

Test #24:

score: 0
Accepted
time: 1ms
memory: 3888kb

input:

1000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

3
3 1 2
4 3 1

result:

ok 

Test #25:

score: 0
Accepted
time: 4ms
memory: 6348kb

input:

9999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

3
3 1 2
4 3 1

result:

ok 

Test #26:

score: 0
Accepted
time: 2ms
memory: 6164kb

input:

10000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
3 1 2
4 3 1

result:

ok 

Test #27:

score: 0
Accepted
time: 32ms
memory: 32832kb

input:

97065
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
3 1 2
4 3 1

result:

ok 

Test #28:

score: 0
Accepted
time: 20ms
memory: 33952kb

input:

99999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
3 1 2
4 3 1

result:

ok 

Test #29:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

7
1 2
2 3
3 4
4 5
5 6
6 7
7 5
7 4
7 3
7 2
7 1

output:

3
5 6 7
7 1 2

result:

ok 

Test #30:

score: 0
Accepted
time: 35ms
memory: 33660kb

input:

100000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 5...

output:

3
99998 99999 100000
100000 1 2

result:

ok 

Test #31:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

8
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 6
8 5
8 4
8 3
8 2
8 1

output:

3
6 7 8
8 1 2

result:

ok 

Test #32:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 7
9 6
9 5
9 4
9 3
9 2
9 1

output:

3
7 8 9
9 1 2

result:

ok 

Test #33:

score: 0
Accepted
time: 0ms
memory: 3636kb

input:

10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 8
10 7
10 6
10 5
10 4
10 3
10 2
10 1

output:

3
8 9 10
10 1 2

result:

ok 

Test #34:

score: 0
Accepted
time: 1ms
memory: 3920kb

input:

1000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

3
998 999 1000
1000 1 2

result:

ok 

Test #35:

score: 0
Accepted
time: 2ms
memory: 6192kb

input:

9999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53
...

output:

3
9997 9998 9999
9999 1 2

result:

ok 

Test #36:

score: 0
Accepted
time: 0ms
memory: 6184kb

input:

10000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
9998 9999 10000
10000 1 2

result:

ok 

Test #37:

score: 0
Accepted
time: 32ms
memory: 31724kb

input:

92892
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
92890 92891 92892
92892 1 2

result:

ok 

Test #38:

score: 0
Accepted
time: 39ms
memory: 33536kb

input:

99999
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51 52
52 53...

output:

3
99997 99998 99999
99999 1 2

result:

ok 

Test #39:

score: -100
Wrong Answer
time: 0ms
memory: 3644kb

input:

8
5 6
7 3
2 3
7 8
1 5
2 8
8 5
4 5
8 1
7 6
3 4
2 6
2 1

output:

3
1 8 2
1 8 2

result:

wrong answer Wrong output - Identical cycle.