Submission #812082

#TimeUsernameProblemLanguageResultExecution timeMemory
812082vjudge1Olympic Bus (JOI20_ho_t4)C++17
37 / 100
1088 ms87164 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[209][209] ,us[N][209] ,  a[N] = {}, dp[N] ,  b[N] , c[N] , p[N];

vector<int>v[N][2] ;
ll M;

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;
    set<pair<ll,int>>st;
    d[x][p] = 0;
    st.insert({0 , x});
    ll check = 0;
    while(!st.empty()){
        x = st.begin()->se  , f = st.begin()->fi;
        st.erase(st.begin());
        if(d[x][p] != f)
            continue;
        if(p == 0 && x == n)
            break;
        if(p == 2 && x == 1)
            break;
         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.insert({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 x, int n){
    check[x] = us[i][x];
    if(us[i][x]){
        if(x == 0)
            dijkstra(1 , 0 , 0 , i,  n);
        if(x == 1)
            dijkstra(1 , 1 , 1 , i,  n);
        if(x == 2)
            dijkstra(n , 0 , 2 , i ,  n);
        if(x == 3)
            dijkstra(n , 1 , 3 , i ,  n);
            cnt++;
    }
}


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);
    //cout<<d[1][2]<<"\n";
    mn = d[n][0] + d[1][2];
    //cout<<mn<<"\n";
    for(i = 1; i <= m; i++){
        for(j = 0; j < 4; j++)
            check[j] = 0;
        get(i , 0 , n);
        get(i , 1 , n);
        get(i , 2 , n);
        get(i , 3 , n);
        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]);
        if(check[0])
            dijkstra(1 , 0 , 0 , -1,  n);
        if(check[1])
            dijkstra(1 , 1 , 1 , -1,  n);
        if(check[2])
            dijkstra(n , 0 , 2 , -1 ,  n);
        if(check[3])
            dijkstra(n , 1 , 3 , -1 ,  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:32:12: warning: unused variable 'j' [-Wunused-variable]
   32 |     ll i , j , m , s , f ,l , r , y;
      |            ^
ho_t4.cpp:32:16: warning: unused variable 'm' [-Wunused-variable]
   32 |     ll i , j , m , s , f ,l , r , y;
      |                ^
ho_t4.cpp:32:20: warning: unused variable 's' [-Wunused-variable]
   32 |     ll i , j , m , s , f ,l , r , y;
      |                    ^
ho_t4.cpp:32:27: warning: unused variable 'l' [-Wunused-variable]
   32 |     ll i , j , m , s , f ,l , r , y;
      |                           ^
ho_t4.cpp:32:31: warning: unused variable 'r' [-Wunused-variable]
   32 |     ll i , j , m , s , f ,l , r , y;
      |                               ^
ho_t4.cpp:42:8: warning: unused variable 'check' [-Wunused-variable]
   42 |     ll check = 0;
      |        ^~~~~
ho_t4.cpp: In function 'void get(int, int, int)':
ho_t4.cpp:81:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   81 |         if(x == 3)
      |         ^~
ho_t4.cpp:83:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   83 |             cnt++;
      |             ^~~
ho_t4.cpp: In function 'void solve()':
ho_t4.cpp:89:8: warning: unused variable 'q' [-Wunused-variable]
   89 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |        ^
ho_t4.cpp:89:26: warning: unused variable 'z' [-Wunused-variable]
   89 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                          ^
ho_t4.cpp:89:29: warning: unused variable 's' [-Wunused-variable]
   89 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                             ^
ho_t4.cpp:89:37: warning: unused variable 'f' [-Wunused-variable]
   89 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                     ^
ho_t4.cpp:89:41: warning: unused variable 'l' [-Wunused-variable]
   89 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                         ^
ho_t4.cpp:89:45: warning: unused variable 'r' [-Wunused-variable]
   89 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                             ^
ho_t4.cpp:89:49: warning: unused variable 'k' [-Wunused-variable]
   89 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                 ^
ho_t4.cpp:89:74: warning: unused variable 'mx' [-Wunused-variable]
   89 |     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...