Raslboyy

1967

Nov 7th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #include <iostream>
  2. //#include <chrono>
  3. //#include <fstream>
  4. //#include <bits/stdc++.h>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8. #define mp make_pair
  9. #define pb push_back
  10. #define eb emplace_back
  11. #define f first
  12. #define s second
  13. #define sz(x) (int)x.size()
  14. #define all(x) begin(x), end(x)
  15. #define rall(x) rbegin(x), rend(x)
  16.  
  17. using namespace std;
  18.  
  19. typedef unsigned long long ull;
  20. typedef long long ll;
  21. typedef long double ld;
  22. typedef pair<int, int> pi;
  23. typedef pair<ll, ll> pl;
  24. const int INF = 1e18;
  25.  
  26. vector<vector<pi>> mat;
  27. int n;
  28.  
  29. bool foo(int count_cup) {
  30.     vector<ll> d(n, INF);
  31.     d[0] = 0;
  32.     vector<bool> used(n);
  33.     for (int i = 0; i < n; i++) {
  34.         int v = -1;
  35.         for (int j = 0; j < n; j++)
  36.             if ((v == -1 || d[j] < d[v]) && !used[j])
  37.                 v = j;
  38.         if (d[v] == INF)
  39.             break;
  40.         used[v] = 1;
  41.         for (int j = 0; j < n; j++)
  42.             if ((ll)mat[v][j].first + d[v] < d[j] && mat[v][j].second >= count_cup)
  43.                 d[j] = (ll)mat[v][j].first + d[v];
  44.     }
  45.     return d[n - 1] <= 1440;
  46. }
  47.  
  48. int main() {
  49.     /*ifstream cin("in.txt");
  50.     ofstream cout("out.txt");
  51.     auto start_time = chrono::high_resolution_clock::now();*/
  52.  
  53.     ios::sync_with_stdio(false);
  54.     cin.tie(0);
  55.     cout.tie(0);
  56.  
  57.     int m;
  58.     cin >> n >> m;
  59.     if (m == 0 || n == 1) {
  60.         cout << int(1e7) << "\n";
  61.         return 0;
  62.     }
  63.     mat.assign(n, vector<pi>(n));
  64.     for (int i = 0; i < m; i++) {
  65.         int a, b, c, d;
  66.         cin >> a >> b >> c >> d;
  67.         d = (d - 3e6) / 100;
  68.         mat[--a][--b] = mp(c, d);
  69.         mat[b][a] = mp(c, d);
  70.     }
  71.  
  72.     int l = 0, r = 10000100;
  73.     while (l < r) {
  74.         int mid = (l + r) / 2;
  75.         if (foo(mid))
  76.             l = mid + 1;
  77.         else
  78.             r = mid;
  79.     }
  80.     cout << max(0, l - 1) << "\n";
  81.  
  82.     /*auto end_time = chrono::high_resolution_clock::now();
  83.     chrono::duration<double> duration = end_time - start_time;
  84.     cout << duration.count() << "\n";
  85.     cin.close();
  86.     cout.close();*/
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment