Submission #812372

#TimeUsernameProblemLanguageResultExecution timeMemory
812372vjudge1Olympic Bus (JOI20_ho_t4)C++17
100 / 100
931 ms10060 KiB
#include <bits/stdc++.h> using namespace std; #define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define rall(s) s.rbegin(),s.rend() #define all(s) s.begin(),s.end() #define pb push_back #define fi first #define se second #define ll long long #define ld long double #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define yes cout<<"yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define no cout<<"no\n" const int N = 5e4 + 9 , mod = 1e9 + 7; ll d[N][10] ,us[N][10] , a[N] = {}, dp[N] , b[N] , c[N] , p[N]; vector<int>v[N][2] ; ll M , cn = 0; ll A , B , C ; void dijkstra(int x , int k,int p , int o , int n){ ll i , j , m , s , f ,l , r , y; for(i = 1; i <= n; i++){ d[i][p] = 1e15; ::p[i] = 0; } for(i = 1; i <= M; i++) us[i][p] = 0; priority_queue<pair<ll,int>>st; d[x][p] = 0; st.push({0 , x}); ll check = 0; while(!st.empty()){ x = st.top().se , f = -st.top().fi; st.pop(); if(d[x][p] != f) continue; if(p == 0 && x == n) break; if(p == 2 && x == 1) break; if(x == A){ if(d[A][p] + C < d[B][p]){ ::p[B] = -1; d[B][p] = d[A][p] + C; st.push({-d[B][p] , B}); } } for(auto to : v[x][k]){ if(to == o) continue; if(k == 0) y = b[to]; else y = a[to]; if(d[x][p] + c[to] < d[y][p]){ ::p[y]= to; d[y][p] = d[x][p] + c[to]; st.push({-d[y][p] , y}); } } } for(i = 1; i <= n; i++){ us[::p[i]][p] = 1; } } ll cnt = 0; ll check[4] = {}; void get(int i , int n){ check[0] = check[2] = 1; dijkstra(1 , 0 , 0 , i, n); dijkstra(n , 0 , 2 , i, n); } void add(int j , int n , int m){ int i ; for(i = 1; i <= n; i++) d[i][j] = d[i][j + 4]; for(i = 1; i <= m; i++) us[i][j] = us[i][j + 4]; } void solve(){ ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn = 1e18 , mx = 0; cin>>n>>m; M = m; for(i = 1; i <= m; i++){ cin>>a[i]>>b[i]>>c[i]>>dp[i]; v[a[i]][0].pb(i); v[b[i]][1].pb(i); } dijkstra(1 , 0 , 0 , -1, n); dijkstra(1 , 1 , 1 , -1, n); dijkstra(n , 0 , 2 , -1 , n); dijkstra(n , 1 , 3 , -1 , n); for(i = 1; i <= n; i++) for(j = 0; j < 4; j++) d[i][j + 4] = d[i][j]; for(i = 1; i <= m; i++) for(j = 0; j < 4; j++) us[i][j + 4] = us[i][j]; mn = d[n][0] + d[1][2]; for(i = 1; i <= m; i++){ for(j = 0; j < 4; j++) check[j] = 0; if(us[i][0] || us[i][2]){ A = b[i]; B = a[i]; C = c[i]; get(i , n); A = B = C = -1; mn = min(mn , d[n][0] + d[1][2] + dp[i]); // cout<<d[n][0]<<"\n"; for(j = 0; j < 4; j++) if(check[j]) add(j , n , m); continue; } x = min(d[n][0] , d[b[i]][0] + d[a[i]][3] + c[i]); y= min(d[1][2] , d[b[i]][2] + d[a[i]][1] + c[i]); mn = min(mn , x + y + dp[i]); } // cout<<cnt<<"\n"; if(mn >= 1e15) mn = -1; cout<<mn<<"\n"; } int main(){ TL; /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif */ int t = 1; //cin>>t; while(t--) { solve(); } } // Author : حسن

Compilation message (stderr)

ho_t4.cpp: In function 'void dijkstra(int, int, int, int, int)':
ho_t4.cpp:33:12: warning: unused variable 'j' [-Wunused-variable]
   33 |     ll i , j , m , s , f ,l , r , y;
      |            ^
ho_t4.cpp:33:16: warning: unused variable 'm' [-Wunused-variable]
   33 |     ll i , j , m , s , f ,l , r , y;
      |                ^
ho_t4.cpp:33:20: warning: unused variable 's' [-Wunused-variable]
   33 |     ll i , j , m , s , f ,l , r , y;
      |                    ^
ho_t4.cpp:33:27: warning: unused variable 'l' [-Wunused-variable]
   33 |     ll i , j , m , s , f ,l , r , y;
      |                           ^
ho_t4.cpp:33:31: warning: unused variable 'r' [-Wunused-variable]
   33 |     ll i , j , m , s , f ,l , r , y;
      |                               ^
ho_t4.cpp:43:8: warning: unused variable 'check' [-Wunused-variable]
   43 |     ll check = 0;
      |        ^~~~~
ho_t4.cpp: In function 'void solve()':
ho_t4.cpp:125:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  125 |         for(j = 0; j < 4; j++)
      |         ^~~
ho_t4.cpp:128:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  128 |             continue;
      |             ^~~~~~~~
ho_t4.cpp:95:8: warning: unused variable 'q' [-Wunused-variable]
   95 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |        ^
ho_t4.cpp:95:26: warning: unused variable 'z' [-Wunused-variable]
   95 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                          ^
ho_t4.cpp:95:29: warning: unused variable 's' [-Wunused-variable]
   95 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                             ^
ho_t4.cpp:95:37: warning: unused variable 'f' [-Wunused-variable]
   95 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                     ^
ho_t4.cpp:95:41: warning: unused variable 'l' [-Wunused-variable]
   95 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                         ^
ho_t4.cpp:95:45: warning: unused variable 'r' [-Wunused-variable]
   95 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                             ^
ho_t4.cpp:95:49: warning: unused variable 'k' [-Wunused-variable]
   95 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                 ^
ho_t4.cpp:95:74: warning: unused variable 'mx' [-Wunused-variable]
   95 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                                          ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...