Advertisement
Saleh127

UVA 436 / Floyd-Warshall

Jun 17th, 2022
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. /***
  2.  created: 2022-06-17-23.32.09
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10. template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
  11. #define ll long long
  12. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  13. #define get_lost_idiot return 0
  14. #define nl '\n'
  15.  
  16.  
  17. int main()
  18. {
  19.     ios_base::sync_with_stdio(0);
  20.     cin.tie(0);
  21.     cout.tie(0);
  22.  
  23.     ll n,tt=0;
  24.  
  25.     while(cin>>n && n)
  26.     {
  27.         double a[n+2][n+2],vl;
  28.  
  29.         ll p[n+2][n+2][n+2],i,j,k,l=0,m;
  30.  
  31.         memset(a,0,sizeof a);
  32.  
  33.         map<string,ll>x;
  34.         for(i=0; i<n; i++)
  35.         {
  36.             string s;
  37.             cin>>s;
  38.             x[s]=i+1;
  39.         }
  40.  
  41.         cin>>m;
  42.  
  43.         for(i=0; i<m; i++)
  44.         {
  45.             string s,ss;
  46.  
  47.             cin>>s>>vl>>ss;
  48.  
  49.             a[x[s]][x[ss]]=vl;
  50.  
  51.         }
  52.  
  53.         for(i=1; i<=n; i++)
  54.         {
  55.             for(j=1; j<=n; j++)
  56.             {
  57.                 for(k=1; k<=n; k++)
  58.                 {
  59.                     a[i][j]=max(a[i][j],a[i][k]*a[k][j]);
  60.                 }
  61.             }
  62.         }
  63.  
  64.         for(i=1; i<=n; i++) if(a[i][i]>1.00) l=1;
  65.  
  66.         cout<<"Case "<<++tt<<": ";
  67.         if(!l) cout<<"No"<<nl;
  68.         else
  69.         {
  70.             cout<<"Yes"<<nl;
  71.         }
  72.     }
  73.  
  74.     get_lost_idiot;
  75. }
  76.  
  77.  
  78. /*
  79.  
  80. 3
  81. USDollar
  82. BritishPound
  83. FrenchFranc
  84. 3
  85. USDollar 0.5 BritishPound
  86. BritishPound 10.0 FrenchFranc
  87. FrenchFranc 0.21 USDollar
  88. 3
  89. USDollar
  90. BritishPound
  91. FrenchFranc
  92. 6
  93. USDollar 0.5 BritishPound
  94. USDollar 4.9 FrenchFranc
  95. BritishPound 10.0 FrenchFranc
  96. BritishPound 1.99 USDollar
  97. FrenchFranc 0.09 BritishPound
  98. FrenchFranc 0.19 USDollar
  99. 0
  100.  
  101. */
  102.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement