-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathARBITRAG.cpp
More file actions
47 lines (47 loc) · 926 Bytes
/
ARBITRAG.cpp
File metadata and controls
47 lines (47 loc) · 926 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
#include <bits/stdc++.h>
using namespace std;
int main(){
for(int test = 1; ; test++){
int n;
scanf("%d",&n);
if(n == 0)
return 0;
map<string , int> m;
string s , source , dest;
for(int i = 0 ; i < n ; i++){
cin>>s;
m[s] = i;
}
int table;
cin>>table;
double dist[50][50] , cost ;
for(int i = 0 ; i < n ; i++){
for(int j = 0 ; j < n ; j++){
dist[i][j] = 0.0;
}
}
for(int i = 0 ; i < table ; i++){
cin>>source>>cost>>dest;
int x , y;
x = m[source];
y = m[dest];
dist[x][y] = cost;
}
//floyd warshall
for(int k = 0 ; k < n ; k++)
for(int i = 0 ; i < n ; i++)
for(int j = 0 ; j < n ; j++)
dist[i][j] = max(dist[i][j] , dist[i][k] * dist[k][j]);
int flag = 0;
for(int i = 0 ; i < n ; i++){
if(dist[i][i] > 1.0 ){
flag = 1;
break;
}
}
if(flag)
cout<<"Case "<<test<<": Yes\n";
else
cout<<"Case "<<test<<": No\n";
}
}