-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10171.cpp
More file actions
executable file
·99 lines (89 loc) · 2.17 KB
/
10171.cpp
File metadata and controls
executable file
·99 lines (89 loc) · 2.17 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<bits/stdc++.h>
using namespace std;
#define PII pair<int,int>
int INF=INT_MAX;
int dijkstra(vector<PII> start[],int src,int dest)
{
priority_queue<PII,vector<PII>,greater<PII>> Q;
vector<int> p(27,-1);
vector<int> d(27,INF);
d[src]=0;
Q.push({0,src});
while(!Q.empty())
{
int v=Q.top().second;
int d_v=Q.top().first;
Q.top();
if(d_v!=d[v])continue;
for(auto u:start[v])
{
int to=u.first;
int len=u.second;
if(d[v]+len<d[to])
{
d[to]=d[v]+len;
p[to]=v;
Q.push({d[to],to});
}
}
}
int ans=0;
while(p[dest]!=-1)
{
int y=p[dest];
ans=(ans|(1<<y));
dest=y;
}
return ans;
}
int main()
{
int n;
while(cin>>n)
{
if(n==0)return 0;
vector<PII> start,end;
char aa,bb,cc,dd;
int ww;
int e=n;
while(n--)
{
cin>>aa>>bb>>cc>>dd>>ww;
if(aa=='Y')
{
if(bb=='B')
{
start[cc-'A'].push_back({dd-'A',ww});
start[dd-'A'].push_back({cc-'A',ww});
}
else start[cc-'A'].push_back({dd-'A',ww});
}
else{
if(bb=='B')
{
end[cc-'A'].push_back({dd-'A',ww});
end[dd-'A'].push_back({cc-'A',ww});
}
else end[cc-'A'].push_back({dd-'A',ww});
}
}
map<cchar,int> mp;
for(int i=0; i<26)
cin>>aa>>bb;
int src,dest;
src=aa-'A';
dest=bb-'A';
int A,B;
A=dijkstra(start,src,dest);
B=dijkstra(end,src,dest);
if((A&B)!=0)
{
int C=A&B;
int temp=0;
while(temp<32)
{
if((C&(1<<temp))!=0)cout<<
}
}
}
}