/*ㅤ∧_∧
( ・∀・)
( つ┳⊃
ε (_)へ⌒ヽフ
( ( ・ω・)
◎―◎ ⊃ ⊃
BePhuongSuperSuwi
From TK4 - CHT
ㅤㅤ/ ⌒\____
/・ ) \
/ノへ ノ /|
ノ \\ |/_/_/*/
#include<bits/stdc++.h>
#define task "main"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define int long long
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii, ii>
#define base 341
#define MASK(i) (1ll << i)
#define oo 1e18
#define isOn(x,i) ((x) & MASK(i))
#define bitOn(x,i) ((x) | MASK(i))
#define bitOff(x,i) ((x) & ~MASK(i))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
using namespace std;
//using namespace __gnu_pbds;
const int maxn = 1e6 + 5;
int n, m, s, t, u, v, dists[maxn], distt[maxn], distu[maxn], distv[maxn];
vector <ii> g[maxn];
void djk(int st, int dist[])
{
priority_queue <ii, vector <ii>, greater <ii>> q;
for (int i = 1; i <= n; i++) dist[i] = oo;
dist[st] = 0;
q.push({0, st});
while(!q.empty()) {
int cost = q.top().fi, z = q.top().se;
q.pop();
if (cost > dist[z]) continue;
for (auto e : g[z]) {
int x = e.fi, y = e.se;
if (dist[x] > dist[z] + y) {
dist[x] = dist[z] + y;
q.push({dist[x], x});
}
}
}
}
iii ed[maxn];
vector <int> adj[maxn], ans;
int vs[maxn], dp1[maxn], dp2[maxn];
void dfs(int u) {
vs[u] = 1;
for (int x : adj[u]) {
if (!vs[x])
dfs(x);
}
vs[u] = 2;
ans.pb(u);
}
main() {
ios_base::sync_with_stdio(0);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 l, r, z;
cin >> l >> r >> z;
g[l].pb({r, z});
g[r].pb({l, z});
ed[i] = {l, {r, z}};
}
djk(s, dists);
djk(t, distt);
djk(u, distu);
djk(v, distv);
// cout << dists[6] << endl;
for (int i = 1; i <= m; i++) {
int l = ed[i].fi, r = ed[i].se.fi, z = ed[i].se.se;
if (dists[l] + z + distt[r] == dists[t]) {
adj[r].pb(l);
// cout << l << " " << r << endl;
}
else if (dists[r] + z + distt[l] == dists[t]) {
adj[l].pb(r);
}
}
for (int i = 1; i <= n; i++) {
if (!vs[i]) dfs(i);
}
// cout << distu[1] << " " << distv[5] << endl;
int mini = distu[v];
for (int b : ans) {
dp1[b] = distu[b], dp2[b] = distv[b];
for (int a : adj[b]) {
mini = min({mini, dp1[a] + distv[b], dp2[a] + distu[b]});
dp1[b] = min(dp1[b], dp1[a]);
dp2[b] = min(dp2[b], dp2[a]);
}
}
cout << mini;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp:77:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
77 | main() {
| ^~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |