1032

#include 
#include 
#include 
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;
} 

 

你可能感兴趣的:(1032)