Skip to content

Instantly share code, notes, and snippets.

@hyfrey
Created September 13, 2012 08:22
Show Gist options
  • Save hyfrey/3712845 to your computer and use it in GitHub Desktop.
Save hyfrey/3712845 to your computer and use it in GitHub Desktop.
pat 1032
#include <stdio.h>
int node[100010];
char hash[100010];
int main()
{
int start_a, start_b;
int i, n;
int a, b;
char item;
scanf("%d %d %d",&start_a,&start_b,&n);
for(i = 0; i < n; i++) {
scanf("%d %s %d", &a, &item, &b);
node[a] = b;
}
while(start_a != -1) {
hash[start_a] = 1;
start_a = node[start_a];
}
while(start_b != -1) {
if(hash[start_b]) {
printf("%05d\n",start_b);
return 0;
}
start_b = node[start_b];
}
puts("-1");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment