#include<bits/stdc++.h>
#define bl bool
#define db double
#define fl float
#define st string
#define pb push_back
#define pf push_front
#define is insert
#define endl "\n"
#define pba pop_back
#define pfr pop_front
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define FOR(i, l, r, st) for(int i = l; i <= r; i += st)
#define FOS(i, l, r, sl) for(int i = l; i >= r; i -= sl)
#define mii map<int, int>
#define us unordered_set
#define pii pair<int, int>
#define vt vector
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int INF = 1e18;
void suncuti() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
void fre() {
if(fopen("name.INP", "r")) {
freopen("name.INP", "r", stdin);
freopen("name.OUT", "w", stdout);
}
}
int n, m, A, B, C, D;
vt<pii> kt[maxn];
int trace[maxn];
set<pii> seen;
int dp[maxn], dp2[maxn];
void dij() {
fill(dp, dp + n + 1, INF);
memset(trace, -1, sizeof(trace));
dp[A] = 0;
priority_queue<pii, vt<pii>, greater<pii>> q;
q.push({0, A});
while(q.size()) {
int c = q.top().fi, u = q.top().se;
q.pop();
if(c > dp[u]) continue;
for(auto v : kt[u]) {
int cost = v.se + dp[u];
if(cost < dp[v.fi]) {
dp[v.fi] = cost;
trace[v.fi] = u;
q.push({dp[v.fi], v.fi});
}
}
}
}
vt<int> path;
void bfs() {
fill(dp2, dp2 + n + 1, INF);
dp2[C] = 0;
deque<int> d;
d.pf(C);
while(d.size()) {
int u = d.front(); d.pfr();
for(auto v : kt[u]) {
int cost = dp2[u];
if(seen.count({u, v.fi}) || seen.count({v.fi, u})) cost = cost;
else cost += v.se;
if(cost < dp2[v.fi]) {
dp2[v.fi] = cost;
if(cost == dp2[u]) d.pf(v.fi);
else d.pb(v.fi);
}
}
}
}
main() {
suncuti();
cin >> n >> m;
cin >> A >> B;
cin >> C >> D;
FOR(i, 1, m, 1) {
int u, v, w;
cin >> u >> v >> w;
kt[u].pb({v, w});
kt[v].pb({u, w});
}
dij();
int kit = B;
while(kit != -1) {
path.pb(kit);
kit = trace[kit];
}
reverse(path.begin(), path.end());
FOR(i, 1, path.size() - 1, 1) {
seen.is({path[i], path[i - 1]});
seen.is({path[i - 1], path[i]});
}
bfs();
cout << dp2[D];
}
Compilation message (stderr)
commuter_pass.cpp:26:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
26 | const int INF = 1e18;
| ^~~~
commuter_pass.cpp:90:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
90 | main() {
| ^~~~
commuter_pass.cpp: In function 'void fre()':
commuter_pass.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen("name.INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen("name.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... |