Submission #1101201

#TimeUsernameProblemLanguageResultExecution timeMemory
1101201KasymKCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
180 ms21236 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 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].pb({b, c}); adj[b].pb({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); for(auto &i : A){ int a, b, c; tie(a, b, c) = i; if(diss[a]+dis[b]+c==diss[t]){ adj[a].pb({b, 0}); adj[b].pb({a, 0}); } } dij(u); assert(~possible); printf("%lld\n", min(possible, dis[v])); return 0; }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:43:7: 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:8: 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...