제출 #812045

#제출 시각아이디문제언어결과실행 시간메모리
812045vjudge1Olympic Bus (JOI20_ho_t4)C++17
26 / 100
1080 ms11612 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]; 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; } set<pair<ll,int>>st; d[x][p] = 0; st.insert({0 , x}); while(!st.empty()){ x = st.begin()->se , f = st.begin()->fi; st.erase(st.begin()); if(d[x][p] != f) continue; 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]){ if(st.find({d[y][p] , y}) != st.end()) st.erase({d[y][p] , y}); ::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 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); } } void solve(){ ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn = 1e18 , mx = 0; cin>>n>>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); //if(i == 3){ // cout<<a[i]<<" "<<b[i]<<" "<<"\n"; // cout<<b[i]<<" "<<d[b[i]][0]<<" "<<"\n"; // cout<<a[i]<<" "<<d[a[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]); //cout<<x<<" "<<y<<"\n"; 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 : حسن

컴파일 시 표준 에러 (stderr) 메시지

ho_t4.cpp: In function 'void dijkstra(int, int, int, int, int)':
ho_t4.cpp:31:12: warning: unused variable 'j' [-Wunused-variable]
   31 |     ll i , j , m , s , f ,l , r , y;
      |            ^
ho_t4.cpp:31:16: warning: unused variable 'm' [-Wunused-variable]
   31 |     ll i , j , m , s , f ,l , r , y;
      |                ^
ho_t4.cpp:31:20: warning: unused variable 's' [-Wunused-variable]
   31 |     ll i , j , m , s , f ,l , r , y;
      |                    ^
ho_t4.cpp:31:27: warning: unused variable 'l' [-Wunused-variable]
   31 |     ll i , j , m , s , f ,l , r , y;
      |                           ^
ho_t4.cpp:31:31: warning: unused variable 'r' [-Wunused-variable]
   31 |     ll i , j , m , s , f ,l , r , y;
      |                               ^
ho_t4.cpp: In function 'void solve()':
ho_t4.cpp:82:8: warning: unused variable 'q' [-Wunused-variable]
   82 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |        ^
ho_t4.cpp:82:26: warning: unused variable 'z' [-Wunused-variable]
   82 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                          ^
ho_t4.cpp:82:29: warning: unused variable 's' [-Wunused-variable]
   82 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                             ^
ho_t4.cpp:82:37: warning: unused variable 'f' [-Wunused-variable]
   82 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                     ^
ho_t4.cpp:82:41: warning: unused variable 'l' [-Wunused-variable]
   82 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                         ^
ho_t4.cpp:82:45: warning: unused variable 'r' [-Wunused-variable]
   82 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                             ^
ho_t4.cpp:82:49: warning: unused variable 'k' [-Wunused-variable]
   82 |     ll q , i , j , m ,n, z ,s = 0 , f , l , r , k , x , y , mn  = 1e18 , mx = 0;
      |                                                 ^
ho_t4.cpp:82:74: warning: unused variable 'mx' [-Wunused-variable]
   82 |     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...