# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1052790 | fauz | Commuter Pass (JOI18_commuter_pass) | C++14 | 156 ms | 41328 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
const int MAXN = 1001;
typedef pair<int, int> II;
int n, m, s, t, u, v;
long long d[MAXN][MAXN];
vector<II> g[MAXN];
set<II> q;
void dijk(int a)
{
q.insert(II(0, a));
d[a][a] = 0;
while (!q.empty())
{
int x = q.begin()->se;
q.erase(q.begin());
for (II node : g[x])
{
int y = node.fi, w = node.se;
if (d[a][y] > d[a][x] + w)
{
if (d[a][y] < LLONG_MAX)
q.erase(II(d[a][y], y));
d[a][y] = d[a][x] + w;
q.insert(II(d[a][y], y));
}
}
}
}
bool clear[MAXN];
int32_t main()
{
if (fopen("inp.txt", "r"))
{
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
cin >> n >> m >> s >> t >> u >> v;
for (int i = 1; i <= m; ++i)
{
int a, b, c;
cin >> a >> b >> c;
g[a].push_back(II(b, c));
g[b].push_back(II(a, c));
}
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
d[i][j] = LLONG_MAX;
vector<int> T;
T.push_back(t);
for (int i = 1; i <= n; ++i)
dijk(i);
long long ans = d[u][v];
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
for (int k = 1; k <= n; ++k)
if (d[s][t] == d[s][k] + d[k][i] + d[i][t] && d[s][t] == d[s][k] + d[k][j] + d[j][t])
ans = min(ans, d[u][i] + d[j][v] + min(d[k][i], d[k][j]));
cout << ans;
}
Compilation message (stderr)
# | 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... |