제출 #306417

#제출 시각아이디문제언어결과실행 시간메모리
306417vipghn2003Commuter Pass (JOI18_commuter_pass)C++14
0 / 100
2084 ms262144 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pii pair<int,int> #define mp make_pair using namespace std; const int N=1e5+5; int n,m,s,t,u,v,deg[N]; long long d[3][N],dp[N]; vector<int>g[N],topolist,rg[N]; vector<pii>adj[N]; void dijkstra(int i,int u) { priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>>pq; d[i][u]=0; pq.push(mp(0,u)); while(!pq.empty()) { int x=pq.top().se; long long dist=pq.top().fi; pq.pop(); if(d[i][x]!=dist) continue; for(auto&to:adj[x]) { if(d[i][to.fi]==-1||d[i][to.fi]>dist+to.se) { d[i][to.fi]=dist+to.se; pq.push(mp(d[i][to.fi],to.fi)); } } } } void topo() { queue<int>pq; for(int i=1;i<=n;i++) if(deg[i]==0) pq.push(i); while(!pq.empty()) { int x=pq.front(); pq.pop(); topolist.push_back(x); for(auto&to:g[x]) { deg[to]--; if(deg[to]==0) pq.push(to); } } } main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin>>n>>m>>s>>t>>u>>v; while(m--) { int u,v,w; cin>>u>>v>>w; adj[u].push_back(mp(v,w)); adj[v].push_back(mp(u,w)); } memset(d,-1,sizeof d); dijkstra(0,u); dijkstra(1,v); dijkstra(2,s); queue<int>cur; cur.push(t); while(!cur.empty()) { int x=cur.front(); cur.pop(); for(auto&to:adj[x]) { if(d[2][x]==d[2][to.fi]+to.se) { g[to.fi].push_back(x); rg[x].push_back(to.fi); deg[x]++; cur.push(to.fi); } } } topo(); long long res=1e18; for(auto&x:topolist) { dp[x]=1e18; if(d[0][x]!=-1) dp[x]=d[0][x]; for(auto&pre:rg[x]) dp[x]=min(dp[x],dp[pre]); if(d[1][x]!=-1) res=min(res,d[1][x]+dp[x]); } cout<<res; }

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

commuter_pass.cpp:53:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   53 | main()
      |      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...