-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday6.cpp
More file actions
75 lines (60 loc) · 1.45 KB
/
day6.cpp
File metadata and controls
75 lines (60 loc) · 1.45 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
ifstream fin("aoc.in");
ofstream fout("aoc.out");
int n,cnt,d[2000],i,j,k,f[2000],you,san;
char x[4],y[4];
char v[2000][4];
vector <int> l[2000];
long long suma;
int niv[2000];
void dfs(int nod){
cnt++;
f[nod]=cnt;
for(int i=0;i<l[nod].size();i++){
int vec=l[nod][i];
if(f[vec]==0)
dfs(vec);
d[nod]+=1+d[vec];
}
cnt--;
}
int main(){
while(fin>>x[1]){
fin>>x[2]>>x[3];
fin>>y[1]>>y[1]>>y[2]>>y[3];
for(i=1;i<=n;i++)
if(x[1]==v[i][1] && x[2]==v[i][2] && x[3]==v[i][3])
break;
if(i>n){
n++;
v[n][1]=x[1];
v[n][2]=x[2];
v[n][3]=x[3];
}
for(j=1;j<=n;j++)
if(y[1]==v[j][1] && y[2]==v[j][2] && y[3]==v[j][3])
break;
if(j>n){
n++;
v[n][1]=y[1];
v[n][2]=y[2];
v[n][3]=y[3];
}
l[i].push_back(j);
l[j].push_back(i);
}
for(i=1;i<=n;i++){
if(v[i][1]=='Y' && v[i][2]=='O' && v[i][3]=='U')
you=i;
if(v[i][1]=='S' && v[i][2]=='A' && v[i][3]=='N')
san=i;
}
dfs(you);
fout<<f[san]-3;
// for(i=1;i<=n;i++)
// cout<<v[i][1]<<v[i][2]<<v[i][3]<<" "<<f[i]<<"\n";
return 0;
}