제출 #461177

#제출 시각아이디문제언어결과실행 시간메모리
461177Killer2501Commuter Pass (JOI18_commuter_pass)C++14
100 / 100
391 ms27192 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define task "asd" #define pll pair<ll, ll> #define pii pair<pll, ll> #define fi first #define se second using namespace std; const ll mod = 1e15+7; const ll N = 2e5+5; const int base = 313; ll n, m, t, k, T, ans, tong, a[N], b[N], s, u, v, d[N][4], dp[N][4]; vector<pll> adj[N]; vector<ll> kq; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } void dij(ll ui, ll id) { for(int i = 1; i <= n; i ++)d[i][id] = mod; priority_queue< pll, vector<pll>, greater<pll> > pq; pq.push({0, ui}); d[ui][id] = 0; while(!pq.empty()) { pll u = pq.top(); pq.pop(); if(u.fi != d[u.se][id])continue; for(pll v : adj[u.se]) { if(d[v.se][id] > u.fi + v.fi) { d[v.se][id] = u.fi + v.fi; pq.push({d[v.se][id], v.se}); } } } } void sol() { cin >> n >> m >> s >> t >> u >> v; for(int i = 1; i <= m; i ++) { ll x, y, w; cin >> x >> y >> w; adj[x].pb({w, y}); adj[y].pb({w, x}); } dij(s, 0); dij(u, 1); dij(v, 2); queue<ll> q; for(int i = 1; i <= n; i ++) { dp[i][0] = dp[i][1] = dp[i][2] = mod; for(pll vi : adj[i]) { if(d[i][0] + vi.fi == d[vi.se][0])++a[vi.se]; } } q.push(s); while(!q.empty()) { ll ui = q.front(); q.pop(); dp[ui][0] = min(dp[ui][0], d[ui][1]); dp[ui][1] = min(dp[ui][1], d[ui][2]); dp[ui][2] = min(dp[ui][2], min(dp[ui][0] + d[ui][2], dp[ui][1] + d[ui][1])); for(pll vi : adj[ui]) { if(d[vi.se][0] == d[ui][0] + vi.fi) { --a[vi.se]; dp[vi.se][0] = min(dp[vi.se][0], dp[ui][0]); dp[vi.se][1] = min(dp[vi.se][1], dp[ui][1]); dp[vi.se][2] = min(dp[vi.se][2], dp[ui][2]); if(!a[vi.se])q.push(vi.se); } } } cout << min(dp[t][2], d[u][2]); } int main() { if(fopen(task".INP", "r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* 5 1 1 2 2 3 3 4 4 5 */

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

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:97:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |        freopen(task".INP", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:98:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |        freopen(task".OUT", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...