#include <bits/stdc++.h>
#define pb push_back
#define rt return
#define fr first
#define sc second
#define endl '\n'
#define what_will_be_will_be() cout << res << endl;
using namespace std;
typedef long int li;
typedef long long ll;
typedef vector<bool> vbl;
typedef vector<long long> vll;
typedef vector<long int> vli;
typedef vector<int> vit;
typedef vector<string> vstr;
typedef string str;
typedef bool bl;
typedef int it;
typedef unsigned long long ull;
typedef unordered_map<long long, long long> mll;
typedef unordered_map<long long, long int> mli;
typedef unordered_map<long long, bool> mbl;
typedef pair<long long, long long> pll;
typedef pair<int, int> pit;
typedef pair<string, string> pst;
typedef vector<string> vstr;
typedef char chr;
typedef long double ldb;
const it maxn = 5e5 + 5;
const it MOD = 1e9 + 7;
const it LOG = 20;
const ll INF = 1e18;
it n, m, u, v, s, t, x, y;
it cnt = 0;
ll ans = INF;
ll w;
ll d[maxn + 5][5];
struct dt
{
it nodee;
ll w;
};
struct cmp
{
bl operator()(dt a, dt b)
{
rt a.w > b.w;
}
};
vector<vector<dt>> adj(maxn + 5);
vector<vector<it>> a(maxn + 5);
ll dp[maxn + 5];
ll dp2[maxn + 5];
it lab[maxn + 5];
pair<pit, ll> edges[maxn + 5];
bl track[maxn + 5];
bl track2[maxn + 5];
void docf()
{
if (ifstream("open.inp"))
{
freopen("open.inp", "r", stdin);
freopen("close.out", "w", stdout);
}
cin >> n >> m >> s >> t >> x >> y;
}
void dijkstra(it st, it label)
{
priority_queue<dt, vector<dt>, cmp> pq;
for (it i = 1; i <= n; ++i)
{
d[i][label] = INF;
}
d[st][label] = 0;
pq.push({st, 0});
while (!pq.empty())
{
auto u = pq.top();
pq.pop();
if (d[u.nodee][label] < u.w)
{
continue;
}
for (auto v : adj[u.nodee])
{
if (u.w + v.w < d[v.nodee][label])
{
d[v.nodee][label] = u.w + v.w;
pq.push({v.nodee, d[v.nodee][label]});
}
}
}
}
ll dfs(it u)
{
if (track[u] == true)
{
rt dp[u];
}
ll ans = d[u][lab[y]];
for (auto v : a[u])
{
ans = min(ans, dfs(v));
}
track[u] = true;
rt dp[u] = ans;
}
ll dfs2(it u)
{
if (track2[u] == true)
{
rt dp2[u];
}
ll ans = d[u][lab[x]];
for (auto v : a[u])
{
ans = min(ans, dfs2(v));
}
track2[u] = true;
rt dp2[u] = ans;
}
void solve()
{
for (it i = 1; i <= m; ++i)
{
cin >> u >> v >> w;
edges[i] = {{u, v}, w};
adj[u].pb({v, w});
adj[v].pb({u, w});
}
lab[s] = 1;
lab[t] = 2;
lab[x] = 3;
lab[y] = 4;
dijkstra(s, 1);
dijkstra(t, 2);
dijkstra(x, 3);
dijkstra(y, 4);
for (it i = 1; i <= m; ++i)
{
u = edges[i].fr.fr;
v = edges[i].fr.sc;
w = edges[i].sc;
if (d[u][lab[s]] + w + d[v][lab[t]] == d[t][lab[s]])
{
a[u].pb(v);
}
if (d[v][lab[s]] + w + d[u][lab[t]] == d[s][lab[t]])
{
a[v].pb(u);
}
}
memset(track, false, sizeof(track));
memset(track2, false, sizeof(track2));
ans = d[x][lab[y]];
for (it u = 1; u <= n; ++u)
{
ans = min(ans, d[u][lab[x]] + dfs(u));
}
for (it u = 1; u <= n; ++u)
{
ans = min(ans, d[u][lab[y]] + dfs2(u));
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
docf();
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void docf()':
commuter_pass.cpp:62:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen("open.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:63:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen("close.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... |