-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy path1032_Sharing (25).cpp
More file actions
50 lines (48 loc) · 837 Bytes
/
1032_Sharing (25).cpp
File metadata and controls
50 lines (48 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
map<int,int> Hash;
map<int,int> Elem;
int main()
{
int A,B;
int n,i;
int s,d;
char emp;
scanf("%d %d %d", &A, &B, &n);
for(i = 0; i < n; i++)
{
scanf("%d %c %d", &s,&emp,&d);
Elem[s] = d;
}
if(A == B) {printf("%05d\n", A); return 0;}
int ok = 0;
while(A != B)
{
if(A == -1 || B == -1)
{
break;
}
if(Hash[A] || Hash[B])
{
ok = 1;
break;
}
Hash[A] = Hash[B] = 1;
A = Elem[A];
B = Elem[B];
}
if(ok)
{
if(Hash[A]) printf("%05d\n", A);
else printf("%05d\n", B);
}
else
{
puts("-1");
}
return 0;
}