AcWing 1516. 共享
原题链接
简单
作者:
og_
,
2020-06-04 17:56:00
,
所有人可见
,
阅读 639
C++ 代码
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
struct node{
char data;
int next;
bool flag;
}node[N];
int main(){
int s1,s2,n;
cin>>s1>>s2>>n;
char data;
int a1,a2;
for(int i = 0;i<n;i++){
cin>>a1>>data>>a2;
node[a1].data=data;
node[a1].next=a2;
node[a1].flag = false;
}
for(int i = s1;i!=-1;i=node[i].next){
node[i].flag = true;
}
for(int i = s2;i!=-1;i=node[i].next){
if(node[i].flag == true) {
printf("%05d",i);
return 0;
}
}
cout<<"-1";
return 0;
}