제출 #1101304

#제출 시각아이디문제언어결과실행 시간메모리
1101304KasymKCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
445 ms35556 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; set<pii> adj[N]; ll dis[N], diss[N]; int n; void dij(int s){ for(int i = 1; i <= n; ++i) dis[i] = INF; priority_queue<pli, vector<pli>, greater<pli>> pq; pq.push({0, s}); dis[s] = 0; while(!pq.empty()){ int x = pq.top().ss; ll val = pq.top().ff; pq.pop(); if(dis[x] != val) continue; tr(it, adj[x]){ int a = it->ff, w = it->ss; if(umin(dis[a], dis[x]+w)) pq.push({dis[a], a}); } } } int main(){ int m, s, t, u, v; scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v); using node = tuple<int, int, int>; vector<node> A; for(int i = 1; i <= m; ++i){ int a, b, c; scanf("%d%d%d", &a, &b, &c); adj[a].insert({b, c}); adj[b].insert({a, c}); A.pb({a, b, c}); } ll possible = -1; dij(u); possible = dis[v]; dij(s); for(int i = 1; i <= n; ++i) diss[i] = dis[i]; dij(t); // dist[i] = dis[i] for(auto &i : A){ int a, b, c; tie(a, b, c) = i; if(diss[a]+dis[b]+c == diss[t]){ if(adj[b].find({a, c}) != adj[b].end()) adj[b].erase({a, c}); if(adj[a].find({b, c}) != adj[a].end()) adj[a].erase({b, c}); adj[a].insert({b, 0}); } if(diss[a]+dis[a] == diss[t]){ if(adj[b].find({a, c}) != adj[b].end()) adj[b].erase({a, c}); if(adj[a].find({b, c}) != adj[a].end()) adj[a].erase({b, c}); adj[b].insert({a, 0}); } } dij(u); printf("%lld\n", min(possible, dis[v])); return 0; }

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

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d%d%d%d%d%d", &n, &m, &s, &t, &u, &v);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         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...