제출 #1007961

#제출 시각아이디문제언어결과실행 시간메모리
1007961phongOlympic Bus (JOI20_ho_t4)C++17
100 / 100
402 ms6992 KiB
#include<bits/stdc++.h> #define ll long long #define int long long const int nmax = 200 + 5, N = 3e5 + 5; const ll oo = 1e18; const int lg = 7, M = 4e3; const int base = 2e5, mod = 998244353; #define pii pair<ll, ll> #define fi first #define se second #define endl "\n" #define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' ';cout << endl using namespace std; multiset<pii> adj[nmax]; struct node{ int u, v, c, d; }a[N]; ll f[nmax][nmax]; int n, m; priority_queue<pii, vector<pii>, greater<pii>> q; ll dp[nmax]; ll dist(int x){ for(int i = 1; i <= n; ++i) dp[i] = oo; q.push({0, x}); dp[x] =0; while(q.size()){ pii tmp = q.top();q.pop(); int u = tmp.se; ll val = tmp.fi; if(val != dp[u]) continue; for(auto [v, w] : adj[u]){ if(dp[v] > dp[u] + w){ dp[v] = dp[u] + w; q.push({dp[v], v}); } } } if(x == 1) return dp[n]; return dp[1]; } main(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); // freopen("code.inp", "r", stdin); // freopen("code.out", "w", stdout); cin >> n >> m; memset(f, 0x3f, sizeof f); for(int i = 1; i <= n; ++i) f[i][i] =0; for(int i = 1; i <= m; ++i){ int u, v, c, d; cin >> u >> v >> c >> d; a[i] = {u, v, c, d}; adj[u].insert({v, c}); f[u][v] = min(f[u][v], 1ll*c); } for(int k = 1; k <= n; ++k){ for(int i = 1; i <= n; ++i){ for(int j = 1; j <= n; ++j){ f[i][j] = min(f[i][j], f[i][k] + f[k][j]); } } } // for(int i = 1; i <= n; ++i){ // for(int j = 1; j <= n; ++j){ // cout << f[i][j] << ' '; // } // cout << endl; // // } ll ans = f[1][n] + f[n][1]; for(int i = 1; i <= m; ++i){ int u = a[i].v, v = a[i].u; ll cur =min(f[1][n], f[1][u] + f[v][n] + a[i].c)+ min(f[n][1], f[n][u] + f[v][1] + a[i].c) + a[i].d; if(cur >= ans) continue; swap(u, v); adj[u].erase(adj[u].find({v, a[i].c})); adj[v].insert({u, a[i].c}); ans = min(ans, dist(1) + dist(n) + a[i].d); swap(u, v); adj[u].erase(adj[u].find({v, a[i].c})); adj[v].insert({u, a[i].c}); } if(ans >= oo / 2) cout << -1; else cout << ans; } /* 4 5 3 1 3 7 3 2 0 4 1 2 5 1 4 2 4 9 3 4 3 9 */

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

ho_t4.cpp:44:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   44 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...