QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#259572#5088. Two ChoreographiesAestivateWA 2ms9792kbC++201.4kb2023-11-21 02:13:352023-11-21 02:13:36

Judging History

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

  • [2023-11-21 02:13:36]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9792kb
  • [2023-11-21 02:13:35]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define F first 
#define S second 
#define pb push_back
#define int long long

vector<int>node[100005];
bool vis[100005];
int dep[100005],pp[100005];
int id[100005];
pair<int,int>ans[100005];
int now=0,t1,t2;

void dfs(int v,int pre){

    pp[v]=pre;
    dep[v]=dep[pre]+1;
    vis[v]=1;
    for(int ii:node[v]){
        if(ii==pre) continue;
        if(!vis[ii]){
            dfs(ii,v);
        }
        else{
            int dd=dep[v]-dep[ii];
            int g1=v,g2=ii;
            if(dep[g1]<dep[g2]) swap(g1,g2);
            dd=abs(dd);
            id[dd]=g1;
            if(ans[dd].F){
                now=dd;t1=g1,t2=g2;
            }
            else ans[dd].F=g1,ans[dd].S=g2;
        }
    }
}

void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n*2-3;i++){
        int g,h;
        cin>>g>>h;
        node[g].pb(h);
        node[h].pb(g);
    }
    dfs(1,1);
    if(!now) {
        now=3;
        t1=id[n-1],t2=id[n];
        pp[t1]=1,pp[1]=t2;
    }
    

    int g1=ans[now].F,h1=ans[now].S;
    swap(g1,h1);swap(t1,t2);
    // cerr<<now<<"\n";
    cout<<now+1<<"\n";
    while(h1!=g1) cout<<h1<<" ",h1=pp[h1];
    cout<<g1<<"\n";

    while(t2!=t1) cout<<t2<<" ",t2=pp[t2];
    cout<<t1<<"\n";
}

signed main(){
    ios::sync_with_stdio(0);cin.tie(0);
    solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6440kb

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: 2ms
memory: 9504kb

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: 1ms
memory: 6360kb

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:

3
6 5 2
5 2 1

result:

ok 

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 9792kb

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:

7
36 29 19 4 2 16 1
36 29 19 4 2 16 1

result:

wrong answer Wrong output - Identical cycle.