이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Nguyen Huu Hoang Minh
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define reset(x) memset(x, 0,sizeof(x))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define N 100005
#define remain(x) if (x > MOD) x -= MOD
#define ii pair<int, int>
#define iiii pair< ii , ii >
#define viiii vector< iiii >
#define vi vector<int>
#define vii vector< ii >
#define bit(x, i) (((x) >> (i)) & 1)
#define Task "test"
#define int long long
using namespace std;
typedef long double ld;
const int inf = LLONG_MAX/2;
const int minf = -1e10;
int n, m;
int s, t, u, v;
vector<ii> g[N];
int ds[N], dv[N], du[N];
bool vst[N];
int ans;
int dp[2][N];
void readfile()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
if (fopen(Task".inp","r"))
{
freopen(Task".inp","r",stdin);
//freopen(Task".out","w",stdout);
}
cin >> n >> m >> s >> t >> u >> v;
for(int i=1; i<=m; i++){
int u, v, z;
cin >> u >> v >> z;
g[u].pb(ii(v,z));
g[v].pb(ii(u,z));
}
}
void djk(int st, int d[]){
fill(vst, vst+100000, false);
priority_queue<ii> q;
q.push({0,st});
while (q.size()){
int u = q.top().se;
int du = q.top().fi;
q.pop();
if (!vst[u]){
vst[u] = 1;
d[u] = -du;
for(auto &i : g[u]) q.push(ii(du-i.se,i.fi));
}
}
}
void djk2(int st, int en){
fill(vst, vst+100001, false);
fill(dp[0], dp[0]+100001, inf);
fill(dp[1], dp[1]+100001, inf);
priority_queue<pair<int,pair<int,int>>> q;
q.push({0,{st,0}});
dp[0][0] = dp[1][0] = inf;
while (q.size()){
int u, c, par;
ii temp;
tie(c,temp) = q.top();
tie(u,par) = temp;
q.pop();
if (!vst[u]){
vst[u] = 1;
ds[u] = -c;
dp[0][u] = min(dp[0][par],du[u]);
dp[1][u] = min(dp[1][par],dv[u]);
for(auto &i : g[u]) q.push({c-i.se,{i.fi,u}});
}
else if (-c == ds[u]){
int tmp1 = min(dp[0][par],du[u]);
int tmp2 = min(dp[1][par],dv[u]);
if (tmp1 + tmp2 < dp[0][u]+dp[1][u]){
dp[0][u] = tmp1;
dp[1][u] = tmp2;
}
}
}
ans = min(ans,dp[0][en]+dp[1][en]);
}
void proc()
{
djk(u,du);
djk(v,dv);
ans = du[v];
djk2(s,t);
djk2(t,s);
cout << ans;
}
signed main()
{
readfile();
proc();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void readfile()':
commuter_pass.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen(Task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |