// ~~ icebear love atttttttttttt ~~
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i, n) for(int i=0; i<(n); ++i)
#define red(i, n) for(int i=(n)-1; i>=0; --i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebearat"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll LLinf = 1e18 + 27092008;
const int N = 1e5 + 5;
int n, m, U, V, S, T;
vector<ii> G[N];
int dist[4][N], dp[N];
vector<int> adj[N];
void dijkstra(int id, int src) {
priority_queue<ii, vector<ii>, greater<ii>> pq;
memset(dist[id], 0x3f, sizeof dist[id]);
dist[id][src] = 0;
pq.push(mp(0, src));
while(!pq.empty()) {
int du, u; tie(du, u) = pq.top(); pq.pop();
for(ii e : G[u]) {
int v, w; tie(v, w) = e;
if (dist[id][v] > dist[id][u] + w) {
dist[id][v] = dist[id][u] + w;
pq.push(mp(dist[id][v], v));
}
}
}
}
void dijkstra2(int id, int src) {
priority_queue<ii, vector<ii>, greater<ii>> pq;
memset(dist[id], 0x3f, sizeof dist[id]);
dist[id][src] = 0;
pq.push(mp(0, src));
while(!pq.empty()) {
int du, u; tie(du, u) = pq.top(); pq.pop();
for(ii e : G[u]) {
int v, w; tie(v, w) = e;
if (dist[0][u] + w + dist[1][v] == dist[0][T]) w = 0;
if (dist[id][v] > dist[id][u] + w) {
dist[id][v] = dist[id][u] + w;
pq.push(mp(dist[id][v], v));
}
}
}
}
void solve() {
cin >> n >> m >> S >> T >> U >> V;
FOR(i, 1, m) {
int u, v, w;
cin >> u >> v >> w;
G[u].pb(mp(v, w));
G[v].pb(mp(u, w));
}
dijkstra(0, S);
dijkstra(1, T);
dijkstra2(2, U);
dijkstra2(3, V);
cout << min(dist[2][V], dist[3][U]);
}
signed 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);
}
int tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
86 | 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... |