mr_dot_convict

10048-Audiophobia-UVa-mr.convict

May 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. /*author* Priyanshu Shrivastav (from IIT Palakkad) *
  2.  * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
  3.  * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
  4.  * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
  5.  * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
  6. When I wrote this, only God and I understood what I was doing
  7.  ** * * * * * * * Now, only God knows * * * * * * */
  8. #include         <bits/stdc++.h>
  9. #pragma GCC      optimize ("Ofast")
  10. #pragma GCC      optimize ("unroll-loops")
  11. #pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  12.  
  13. #define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
  14. #define PREC     cout.precision (10); cout << fixed
  15. #define x        first
  16. #define y        second
  17. using namespace std;
  18. using pii = pair <int, int>;
  19.  
  20. const int N = (int)1e2 + 10;
  21. const int infi = (int)1e9;
  22. int dp[N][N];
  23. int n, m, q;
  24. vector < vector <pii> > Adj;
  25.  
  26. void modFloydWarshall() {
  27.    for (int k = 0; k < n; ++k)
  28.       for (int i = 0; i < n; ++i)
  29.          for (int j = 0; j < n; ++j)
  30.             dp[i][j] = dp[j][i] = min(dp[i][j], max(dp[i][k], dp[k][j]));
  31. }
  32.  
  33. void read() {
  34.    int it = 0;
  35.    while (cin >> n >> m >> q, n || m || q) {
  36.       if (it) cout << '\n';
  37.       ++it;
  38.       Adj.assign(n, vector <pii>());
  39.       int c1, c2, d;
  40.  
  41.       for (int i = 0; i < n; ++i)
  42.          for (int j = 0; j < n; ++j)
  43.             dp[i][j] = infi;
  44.  
  45.       for (int i = 0; i < m; ++i) {
  46.          cin >> c1 >> c2 >> d;
  47.          --c1, --c2;
  48.          Adj[c1].push_back(pii(c2, d));
  49.          Adj[c2].push_back(pii(c1, d));
  50.          dp[c1][c2] = dp[c2][c1] = d;
  51.       }
  52.  
  53.       cout << "Case #" << it << '\n';
  54.       modFloydWarshall();
  55.       while (q--) {
  56.          cin >> c1 >> c2;
  57.          --c1, --c2;
  58.          if (dp[c1][c2] == infi)
  59.             cout << "no path\n";
  60.          else cout << dp[c1][c2] << '\n';
  61.       }
  62.    }
  63. }
  64.  
  65. signed main() {
  66.    IOS; PREC;
  67.    read();
  68.  
  69.     return EXIT_SUCCESS;
  70. }
Add Comment
Please, Sign In to add comment