QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#259575 | #5088. Two Choreographies | Aestivate | WA | 0ms | 6728kb | C++20 | 1.5kb | 2023-11-21 02:22:02 | 2023-11-21 02:22:02 |
Judging History
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 if(dep[v]>dep[ii]){
int dd=dep[v]-dep[ii];
int g1=v,g2=ii;
if(dep[g1]<dep[g2]) swap(g1,g2);
dd=abs(dd);
if(id[dd]){
now=dd;t1=g1,t2=g2;
}
else ans[dd].F=g1,ans[dd].S=g2;
id[dd]=g1;
}
}
}
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=2;
t1=id[n-2],t2=id[n-1];
// cerr<<dep[ans[2].F]<<" "<<dep[ans[2].S]<<"t1,t2\n";
}
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";
if(now==2){
cout<<id[n-2]<<" "<<1<<" "<<id[n-1]<<"\n";
return;
}
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: 0
Wrong Answer
time: 0ms
memory: 6728kb
input:
4 1 2 1 3 1 4 2 3 2 4
output:
3 3 2 1 4 1 0
result:
wrong answer Integer 0 violates the range [1, 4]