제출 #540224

#제출 시각아이디문제언어결과실행 시간메모리
540224krit3379Commuter Pass (JOI18_commuter_pass)C++17
0 / 100
275 ms24604 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; #define N 100005 struct A{ long long a,w,p; bool operator<(const A& o)const{ return w>o.w; } }; priority_queue<A> q; vector<A> g[N]; vector<pair<ll, ll>> graph[100001]; vector<vector<long long>> dis(2,vector<long long>(N,1e18)); ll ds[100001], dp[2][100001], ans; bool visited[100001]; void dijk(int idx,int s){ q.push({s,0}); dis[idx][s]=0; while(!q.empty()){ auto [a,w,p]=q.top(); q.pop(); if(w>dis[idx][a])continue; for(auto x:g[a]){ if(w+x.w<dis[idx][x.a])q.push({x.a,w+x.w}),dis[idx][x.a]=w+x.w; } } } void dijkstra2(ll start, ll end) { fill(dp[0], dp[0] + 100001, LLONG_MAX / 2); fill(dp[1], dp[1] + 100001, LLONG_MAX / 2); fill(visited, visited + 100001, false); priority_queue<pair<ll, pair<ll, ll>>> pq; pq.push({0, {start, 0}}); dp[0][0] = dp[1][0] = LLONG_MAX/ 2; while (!pq.empty()) { ll c, node, par; pair<ll, ll> p; tie(c, p) = pq.top(); tie(node, par) = p; pq.pop(); if (!visited[node]) { visited[node] = true; ds[node] = -c; dp[0][node] = min(dis[0][node], dp[0][par]); dp[1][node] = min(dis[1][node], dp[1][par]); for (auto i : graph[node]) pq.push({c - i.second, {i.first, node}}); } else if (-c == ds[node]) { if (min(dis[0][node], dp[0][par]) + min(dis[1][node], dp[1][par]) <= dp[0][node] + dp[1][node]) { dp[0][node] = min(dis[0][node], dp[0][par]); dp[1][node] = min(dis[1][node], dp[1][par]); } } } ans = min(ans, dp[0][end] + dp[1][end]); } int main() { int n,m,s,t,u,v,i,a,b; long long w; scanf("%d %d %d %d %d %d",&n,&m,&s,&t,&u,&v); for(i=1;i<=m;i++){ scanf("%d %d %lld",&a,&b,&w); g[a].push_back({b,w}); g[b].push_back({a,w}); } dijk(0,u); dijk(1,v); ans = dis[0][v]; dijkstra2(s, t); dijkstra2(t, s); printf("%lld",ans); return 0; }

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

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