이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
#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,d[3][N],dp[N],deg[N];
vector<int>g[N],topolist,rg[N];
vector<pii>adj[N];
void dijkstra(int i,int u)
{
priority_queue<pii,vector<pii>,greater<pii>>pq;
d[i][u]=0;
pq.push(mp(0,u));
while(!pq.empty())
{
int x=pq.top().se;
int 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);
//cout<<to.fi<<' '<<x<<'\n';
}
}
}
topo();
int 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |