1032. Sharing (25)

http://www.patest.cn/contests/pat-a-practise/1033

//8:44
#include <stdio.h>
#include <vector>
using namespace std;

typedef struct{
	char ch;
	int next;
	bool visited;
}NODE;
NODE node[100005];
int s1,s2,n;
int main(){
	scanf("%d%d%d",&s1,&s2,&n);
	for(int i = 0;i < n;i++){
		int addr;
		scanf("%d",&addr);
		getchar();
		scanf("%c%d",&(node[addr].ch),&(node[addr].next));
		node[addr].visited = false;
	}
	for(int p = s1;p!= -1;p = node[p].next){
		node[p].visited = true;
	}
	int addr = -1;
	for(int p = s2;p!=-1;p = node[p].next){
		if(node[p].visited == true){
			addr = p;
			break;
		}
	}
	if(addr >= 0){
		printf("%05d",addr);
	}
	else
		printf("%d",addr);
	return 0;
}


你可能感兴趣的:(解题报告,浙大机试)