제출 #1103603

#제출 시각아이디문제언어결과실행 시간메모리
1103603KasymKCommuter Pass (JOI18_commuter_pass)C++17
100 / 100
280 ms25068 KiB
#include "bits/stdc++.h" using namespace std; #define ff first #define ss second #define all(v) v.begin(), v.end() #define ll long long #define pb push_back #define pii pair<int, int> #define pli pair<ll, int> #define pll pair<ll, ll> #define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i) #define wr puts("----------------") template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N = 1e5+5; const ll INF = 1e18; vector<pii> adj[N]; ll d[N][3], ds[N], dt[N]; int n, m, s, t, u, v; pii come[N][3]; bool check(int x, int y, int w, bool why){ if(why) return ds[y]+w+dt[x]==ds[t]; else return ds[x]+w+dt[y]==ds[t]; } void dij(int s){ for(int i = 1; i <= n; ++i) dt[i] = INF; priority_queue<pli, vector<pli>, greater<pli>> pq; dt[s] = 0; pq.push({0, s}); while(!pq.empty()){ int x = pq.top().ss; ll val = pq.top().ff; pq.pop(); if(dt[x] != val) continue; tr(it, adj[x]){ int a = it->ff, w = it->ss; if(umin(dt[a], dt[x]+w)) pq.push({dt[a], a}); } } } ll solve(bool why){ for(int i = 1; i <= n; ++i) for(int j = 0; j < 3; ++j) d[i][j] = INF; using node = tuple<ll, int, int>; // dttance, node, type priority_queue<node, vector<node>, greater<node>> pq; d[u][0] = 0; pq.push({0, u, 0}); while(!pq.empty()){ int x, type; ll val; tie(val, x, type) = pq.top(); pq.pop(); if(d[x][type] != val) continue; if(type<2 and umin(d[x][type+1], d[x][type])) pq.push({d[x][type+1], x, type+1}); tr(it, adj[x]){ int y = it->ff, w = it->ss; if(type==0 and umin(d[y][0], d[x][0]+w)) pq.push({d[y][0], y, 0}); else if(type==1 and check(x, y, w, why) and umin(d[y][1], d[x][1])) pq.push({d[y][1], y, 1}); else if(type == 2 and umin(d[y][2], d[x][2]+w)) pq.push({d[y][2], y, 2}); } } return d[v][2]; } int main(){ scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v); for(int i = 1; i <= m; ++i){ int a, b, c; scanf("%d%d%d", &a, &b, &c); adj[a].pb({b, c}); adj[b].pb({a, c}); } dij(s); for(int i = 1; i <= n; ++i) ds[i] = dt[i]; dij(t); printf("%lld\n", min(solve(0), solve(1))); return 0; }

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

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:81:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:84:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         scanf("%d%d%d", &a, &b, &c);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...