链表题,复习一下~~
这里的char完全是无用信息啊。。
#include<bits/stdc++.h>
using namespace std;
struct node{
char c;
int next;
}node[100000];
int main(){
int a,b,n;
cin>>a>>b>>n;
int step,temp;
char c;
for(int i=0;i<n;i++){
cin>>step>>c>>temp;
node[step].c=c;
node[step].next=temp;
}
map<int,int>mp;
int p;
while(1){
if(a==-1)break;
mp[a]=1;
a=node[a].next;
}
while(1){
if(b==-1){
printf("-1");
return 0;
}
if(mp[b]==1){
break;
}
b=node[b].next;
}
printf("%05d",b);
return 0;
}