#include<stdio.h>
#include<iostream>
using namespace std;
const int maxn = 100010;
struct NODE{
char data;
int next;
bool flag;
}list[maxn];
int find(NODE* List, int start1, int start2) {
int k = start1;
while (List[k].next != -1) {
List[k].flag = true;
k = List[k].next;
}
k = start2;
while (List[k].next != -1) {
if (List[k].flag == false) k = List[k].next;
else {
return k;
}
}
return -1;
}
int main() {
int start1, start2, n;
if(scanf("%d %d %d", &start1, &start2, &n) == 3)
{
int addr, next;
char data;
for (int i = 0; i < n; i++) {
if(scanf("%d %c %d", &addr, &data, &next) == 3){
list[addr].data = data;
list[addr].next = next;
list[addr].flag = false;
}
}
int common = find(list, start1, start2);
if (common != -1) printf("%05d\n", common);
else printf("-1\n");
}
return 0;
}
不知道为啥子是部分正确,明天有空去看看ac代码,看看扣了1分扣在哪里