이 제출은 이전 버전의 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 = 1e10;
const int minf = -1e10;
int n, m;
int s, t, u, v;
vector<ii> g[N];
int ds[N], dv[N], dt[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(){
for(int i=1; i<=n; i++) ds[i] = dv[i] = dt[i] = 1e17;
ds[s] = 0;
priority_queue<ii, vii, greater<ii>> q;
q.push(ii(0,s));
while (q.size()){
int du = q.top().fi;
int u = q.top().se;
q.pop();
if (du!=ds[u]) continue;
for(auto i : g[u]){
int v = i.fi;
int uv = i.se;
if (ds[v] > du+uv){
ds[v] = du+uv;
q.push(ii(ds[v],v));
}
}
}
int Min_dis = ds[t];
dt[t] = 0;
q.push(ii(0,t));
while (q.size()){
int u = q.top().se;
int du = q.top().fi;
q.pop();
if (du!=dt[u]) continue;
for(auto i : g[u]){
int v = i.fi;
int uv = i.se;
if (dt[v] > du+uv){
dt[v] = du+uv;
q.push(ii(dt[v],v));
}
}
}
dv[v] = 0;
q.push(ii(dv[v],v));
while (q.size()){
int u = q.top().se;
int du = q.top().fi;
q.pop();
if (dv[u]!=du) continue;
for(auto i : g[u]){
int v = i.fi;
int uv = i.se;
bool is_free = false;
if (ds[v]+dt[u]+uv==Min_dis || ds[u]+dt[v]+uv==Min_dis){
is_free = true;
}
if (dv[v] > du + (is_free ? 0 : uv)){
dv[v] = du + (is_free ? 0 : uv);
q.push(ii(dv[v],v));
}
}
}
cout << dv[s];
}
void proc()
{
if (u==s){
djk();
}
}
signed main()
{
readfile();
proc();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void readfile()':
commuter_pass.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | 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... |