Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***
- created: 2022-06-17-23.32.09
- ***/
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
- #define ll long long
- #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
- #define get_lost_idiot return 0
- #define nl '\n'
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- ll n,tt=0;
- while(cin>>n && n)
- {
- double a[n+2][n+2],vl;
- ll p[n+2][n+2][n+2],i,j,k,l=0,m;
- memset(a,0,sizeof a);
- map<string,ll>x;
- for(i=0; i<n; i++)
- {
- string s;
- cin>>s;
- x[s]=i+1;
- }
- cin>>m;
- for(i=0; i<m; i++)
- {
- string s,ss;
- cin>>s>>vl>>ss;
- a[x[s]][x[ss]]=vl;
- }
- for(i=1; i<=n; i++)
- {
- for(j=1; j<=n; j++)
- {
- for(k=1; k<=n; k++)
- {
- a[i][j]=max(a[i][j],a[i][k]*a[k][j]);
- }
- }
- }
- for(i=1; i<=n; i++) if(a[i][i]>1.00) l=1;
- cout<<"Case "<<++tt<<": ";
- if(!l) cout<<"No"<<nl;
- else
- {
- cout<<"Yes"<<nl;
- }
- }
- get_lost_idiot;
- }
- /*
- 3
- USDollar
- BritishPound
- FrenchFranc
- 3
- USDollar 0.5 BritishPound
- BritishPound 10.0 FrenchFranc
- FrenchFranc 0.21 USDollar
- 3
- USDollar
- BritishPound
- FrenchFranc
- 6
- USDollar 0.5 BritishPound
- USDollar 4.9 FrenchFranc
- BritishPound 10.0 FrenchFranc
- BritishPound 1.99 USDollar
- FrenchFranc 0.09 BritishPound
- FrenchFranc 0.19 USDollar
- 0
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement