Advertisement
weCryOPEN

ECOO '19 R1 P4 - Bus Route

Feb 26th, 2020
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int testcasenum = 10;
  5. int N, M;
  6. int stop[500005], t[500005];
  7. vector<int> v[500005];
  8. struct query{
  9.     int val, bus;
  10.     bool operator < (query q) const {
  11.         if(q.val == val){
  12.             return bus > q.bus;
  13.         }
  14.         else{
  15.             return val > q.val;
  16.         }
  17.     }
  18. };
  19. int main(){
  20. //    freopen("DATA41.txt", "r", stdin);
  21. //    freopen("DATA42.txt", "r", stdin);
  22.     while(testcasenum--){
  23.         priority_queue <query> dropoff, pickup;
  24.         cin.sync_with_stdio(0);
  25.         cin.tie(0);
  26.         cin >> N >> M;
  27.         int K = M/40+5;
  28.         for(int i = 1; i<=N; i++){
  29.             t[i] = i*10;
  30.             v[i].clear();
  31.             stop[i] = 0;
  32.             if(i <= K){
  33.                 for(int k = 1; k<=40; k++){
  34.                     pickup.push({t[i], i});
  35.                 }
  36.             }
  37.         }
  38.         for(int i = 1; i<=M; i++){
  39.             int a, b;
  40.             cin >> a >> b;
  41.             v[a].push_back(b);
  42.         }
  43.         for(int i= 1; i<=N; i++){
  44.             vector<int> vec;
  45.             while(dropoff.size() && dropoff.top().val == i){
  46.                 query q = dropoff.top();
  47.                 dropoff.pop();
  48.                 vec.push_back(q.bus);
  49.                 pickup.push({t[q.bus], q.bus});
  50.             }
  51.             for(int n : v[i]){
  52.                 while(pickup.top().val != t[pickup.top().bus]){
  53.                     pickup.push({t[pickup.top().bus], pickup.top().bus});
  54.                     pickup.pop();
  55.                 }
  56.                 query q = pickup.top();
  57.                 pickup.pop();
  58.                 vec.push_back(q.bus);
  59.                 dropoff.push({n, q.bus});
  60.             }
  61.             for(int n : vec){
  62.                 if(stop[n] != i){
  63.                     stop[n] = i;
  64.                     t[n]++;
  65.                 }
  66.             }
  67.         }
  68.         int ans = 1;
  69.         for(int i =1; i<=N; i++){
  70.             ans = t[i] < t[ans] ? i : ans;
  71.         }
  72.         cout<< "Bus #"<< ans << endl;
  73.     }
  74. }
  75. /*
  76. 5 3
  77. 1 2
  78. 2 3
  79. 4 5
  80.  
  81. 16 20
  82. 11 13
  83. 14 15
  84. 4 16
  85. 2 7
  86. 14 16
  87. 7 13
  88. 1 3
  89. 11 13
  90. 13 14
  91. 2 4
  92. 2 8
  93. 5 8
  94. 10 11
  95. 9 14
  96. 2 10
  97. 13 16
  98. 11 14
  99. 6 8
  100. 15 16
  101. 3 8
  102.  
  103. 13 6
  104. 1 7
  105. 2 8
  106. 3 9
  107. 4 10
  108. 5 11
  109. 6 12
  110. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement