-
Notifications
You must be signed in to change notification settings - Fork 0
/
869 - Airline Comparison.cpp
47 lines (45 loc) · 1.1 KB
/
869 - Airline Comparison.cpp
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
#include<iostream>
#include<vector>
#include<algorithm>
#define Size 128
using namespace std;
int main()
{
int t,n,m;
int i,j,k;
char u,v;
cin>>t;
while(t--)
{
cin>>n;
vector<vector<int> > graph1(Size, vector<int>(Size,0));
for(i=0; i<n; i++)
{
cin>>u>>v;
graph1[u][v]=1;
}
for(k=1; k<Size; k++)
for(i=0; i<Size; i++)
for(j=0; j<Size; j++)
if(graph1[i][k] && graph1[k][j])
graph1[i][j]=1;
cin>>m;
vector<vector<int> > graph2(Size, vector<int>(Size,0));
for(i=0; i<m; i++)
{
cin>>u>>v;
graph2[u][v]=1;
}
for(k=1; k<Size; k++)
for(i=0; i<Size; i++)
for(j=0; j<Size; j++)
if(graph2[i][k] && graph2[k][j])
graph2[i][j]=1;
if(graph1==graph2)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
if(t)
cout<<endl;
}
}