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>
using namespace std;
const int N = 100005, M = 200005;
const long long inf = 1e18;
int n, m, s, t, u, v, x, y, z;
vector<int> e[N][2];
vector<long long> o[302];
long long fp;
vector<long long> D(int rt) {
vector<long long> dr;
dr.resize(n + 1, inf);
dr[rt] = 0;
set<pair<long long, int> > s;
s.insert({0, rt});
while(s.size()) {
int dg = (*s.begin()).second;
long long mn = (*s.begin()).first;
s.erase(s.begin());
for(int i = 0; i < e[dg][0].size(); ++i) {
if(mn + e[dg][1][i] < dr[e[dg][0][i]]) {
if(dr[e[dg][0][i]] ^ inf) s.erase(s.find({dr[e[dg][0][i]], e[dg][0][i]}));
dr[e[dg][0][i]] = mn + e[dg][1][i];
s.insert({dr[e[dg][0][i]], e[dg][0][i]});
}
}
}
return dr;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> s >> t >> u >> v;
for(int i = 1; i <= m; ++i) {
cin >> x >> y >> z;
e[x][0].push_back(y);
e[x][1].push_back(z);
e[y][0].push_back(x);
e[y][1].push_back(z);
}
/*
o[0] = D(s);
o[1] = D(t);
o[2] = D(u);
o[3] = D(v);
for(int i = 0; i < 4; ++i) { for(int j = 1; j <= n; ++j) cout << o[i][j] << " "; cout << "\n"; } cout << endl;
*/
for(int i = 1; i <= n; ++i) {
o[i] = D(i);
}
fp = o[u][v];
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
if(o[s][t] == o[s][i] + o[i][j] + o[j][t]) {
fp = min(fp, min(o[u][i] + o[j][v], o[u][j] + o[i][v]));
}
}
}
cout << fp << endl;
return 0;
}
Compilation message (stderr)
commuter_pass.cpp: In function 'std::vector<long long int> D(int)':
commuter_pass.cpp:21:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < e[dg][0].size(); ++i) {
~~^~~~~~~~~~~~~~~~~
# | 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... |