#include<bits/stdc++.h>
using namespace std;
struct node{
char data;
int next;
bool flag;
}Nodes[100000];
int main(){
for(int i = 0 ; i < 100000 ; i++){
Nodes[i].next = -1;
Nodes[i].flag = false;
}
int n , head1 , head2;
cin>>head1>>head2>>n;
while(n--){
int addr;
char data;
int next;
cin>>addr>>data>>next;
Nodes[addr].data = data;
Nodes[addr].next = next;
}
int h1 = head1;
while(h1!=-1){
Nodes[h1].flag = true;
h1 = Nodes[h1].next;
}
int h2 = head2;
while(!Nodes[h2].flag&&h2!=-1){
h2 = Nodes[h2].next;
}
if(h2 == -1)
cout<<-1;
else{
printf("%05d",h2);
}
}
1032 Sharing (25 分)
最新推荐文章于 2024-09-21 21:23:20 发布