1032

版权声明:// Copyright © 2018年 Coding18. All rights reserved. https://blog.csdn.net/Coding18/article/details/86419538
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct Node{
	int address,next;
	char data;
	int flag;
	Node()
	{
		flag = 0;
	}
}node[100010];
int main()
{
	int u,v,n,addr;
	scanf("%d %d %d",&u,&v,&n);
	for(int i = 0; i < n; i++)
	{
		scanf("%d ",&addr);
		scanf("%c%d",&node[addr].data,&node[addr].next);
	}
	for(int i = u; i != -1; i = node[i].next)
	{
		node[i].flag = 1;
	}
	int p;
	for(p = v; p != -1; p = node[p].next)
	{
		if(node[p].flag == 1)
		break;
	}
	if(p != -1)printf("%05d\n",p);
	else printf("-1\n");
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/Coding18/article/details/86419538