Submission #42116

#TimeUsernameProblemLanguageResultExecution timeMemory
42116nonocutCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
620 ms27108 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define X first #define Y second const int maxn = 100005; const ll inf = 1e18; struct node { int x; ll val; node(int _x = 0, ll _val = 0) { x = _x; val = _val; }; bool operator < (node a) const { return a.val<val; } }; int n,m,a,b,c,d; bool vis[maxn]; ll dist[maxn], da[maxn], db[maxn], dc[maxn], dd[maxn]; vector<pair<int,ll>> way[maxn]; priority_queue<node> heap; vector<int> from[maxn]; ll mn[maxn]; ll ans; void sssp(int u) { for(int i=1;i<=n;i++) dist[i] = inf, vis[i] = 0; dist[u] = 0; heap.push(node(u,0)); while(!heap.empty()) { int u = heap.top().x; heap.pop(); if(vis[u]) continue; vis[u] = 1; for(auto t : way[u]) { if(dist[t.X] > dist[u] + t.Y) { dist[t.X] = dist[u] + t.Y; heap.push(node(t.X,dist[t.X])); } } } } void dag(int u) { vis[u] = 1; for(auto t : way[u]) { if(da[t.X] + t.Y == da[u]) { from[t.X].pb(u); if(!vis[t.X]) dag(t.X); } } } void dfs(int u) { vis[u] = 1; mn[u] = dc[u]; for(auto v : from[u]) { if(!vis[v]) dfs(v); mn[u] = min(mn[u], mn[v]); } ans = min(ans, mn[u] + dd[u]); } int main() { scanf("%d%d",&n,&m); scanf("%d%d%d%d",&a,&b,&c,&d); for(int i=0;i<m;i++) { int x,y; ll val; scanf("%d%d%lld",&x,&y,&val); way[x].pb({y,val}); way[y].pb({x,val}); } sssp(a); for(int i=1;i<=n;i++) da[i] = dist[i]; sssp(b); for(int i=1;i<=n;i++) db[i] = dist[i]; sssp(c); for(int i=1;i<=n;i++) dc[i] = dist[i]; sssp(d); for(int i=1;i<=n;i++) dd[i] = dist[i]; for(int i=1;i<=n;i++) vis[i] = 0; dag(b); ans = dc[d]; for(int i=1;i<=n;i++) vis[i] = 0; dfs(a); for(int i=1;i<=n;i++) swap(dc[i], dd[i]); for(int i=1;i<=n;i++) vis[i] = 0; dfs(a); printf("%lld",ans); }

Compilation message (stderr)

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:71:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
commuter_pass.cpp:72:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d%d",&a,&b,&c,&d);
                                  ^
commuter_pass.cpp:75:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%lld",&x,&y,&val);
                                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...