0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 15:56:26 +00:00

P1931 套利

R53832080
This commit is contained in:
Baoshuo Ren 2021-07-21 20:20:06 +08:00 committed by Baoshuo Ren
parent 28889a5392
commit ed22c66a10
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

View File

@ -0,0 +1,46 @@
#include <bits/stdc++.h>
using namespace std;
int n, m, c;
double w, g[35][35];
map<string, int> kv;
string s, s1, s2;
bool floyd() {
for (int k = 1; k <= n; k++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
g[i][j] = max(g[i][j], g[i][k] * g[k][j]);
}
}
}
for (int i = 1; i <= n; i++) {
if (g[i][i] > 1) {
return true;
}
}
return false;
}
int main() {
while (cin >> n, n) {
kv.clear();
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
g[i][j] = i == j ? 1 : 0;
}
}
for (int i = 1; i <= n; i++) {
cin >> s;
kv[s] = i;
}
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> s1 >> w >> s2;
g[kv[s1]][kv[s2]] = w;
}
cout << "Case " << ++c << ": " << (floyd() ? "Yes" : "No") << endl;
}
return 0;
}