A1032 Sharing [链表]

在这里插入图片描述

#include<vector>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<set>
#include<map>
#include<cstring>
#include<string>
#include<queue>
#include<array>
#include<stack>
using namespace std;
const int maxn = 100010;
struct Node
{
	char data;
	int next;
	bool flag;
}node[maxn];
int main()
{
	for (int i = 0; i < maxn; i++)
	{
		node[i].flag = false;
	}
	int s1, s2, n;
	cin >> s1 >> s2 >> n;
	int address, next;
	char data;
	for (int i = 0; i < n; i++)
	{
		cin >> address>> data >> next;
		node[address].data = data;
		node[address].next = next;
	}
	int p;
	for (p = s1; p != -1; p = node[p].next)
	{
		node[p].flag = true;
	}
	for (p = s2; p != -1; p = node[p].next)
	{
		if (node[p].flag)
			break;
	}
	if (p != -1)
		printf("%05d\n", p);
	else
		printf("-1\n");
	return 0;
}


posted @ 2020-07-21 09:27  _Hsiung  阅读(41)  评论(0编辑  收藏  举报