이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Going for full
*/
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
void ran() {
srand(chrono::steady_clock::now().time_since_epoch().count());
}
long long get_rand() {
long long a = rand();
long long b = rand();
return a * (RAND_MAX + 1ll) + b;
}
void usaco() {
freopen("problem.in", "r", stdin);
freopen("problem.out", "w", stdout);
}
template<typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
#define endl '\n'
// #define double long double
#define int long long
// const int MOD = 1000 * 1000 * 1000 + 7;
// const int MOD = 998244353;
// #define cerr if(0) cerr
#define debug(x) cerr << #x << ": " << x << endl;
int n, m;
int s, t, u, v;
const int MXN = 100005;
vector<pair<int, int>> adj[MXN];
int distu[MXN], distv[MXN];
int dists[MXN], distt[MXN];
int dist[MXN];
bool access[MXN];
int result;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> proc;
void src(int no) {
for (int i=1; i<=n; i++) {
dist[i] = LLONG_MAX;
}
proc.push({0, no});
while (!proc.empty()) {
pair<int, int> tr = proc.top();
proc.pop();
int di = tr.first, no = tr.second;
if (dist[no] < di) continue;
dist[no] = di;
for (auto x: adj[no]) {
int ot = x.first;
int od = x.second + di;
if (dist[ot] > od) {
dist[ot] = od;
proc.push({od, ot});
}
}
}
}
int running_v[MXN];
int running_u[MXN];
bool byd(int a, int b) {
return dist[a] < dist[b];
}
void go(int from, int to) {
src(from);
vector<int> proc;
for (int i=1; i<=n; i++) proc.push_back(i);
sort(proc.begin(), proc.end(), byd);
for (auto no: proc) {
running_v[no] = distv[no];
running_u[no] = distu[no];
for (auto x: adj[no]) {
int ot = x.first;
int od = x.second;
if (dist[ot] + od == dist[no]) {
running_u[no] = min(running_u[no], running_u[ot]);
running_v[no] = min(running_v[no], running_v[ot]);
}
}
if (access[no]) {
result = min(result, running_u[no] + distv[no]);
result = min(result, distu[no] + running_v[no]);
}
}
}
signed main() {
cin >> n >> m;
cin >> s >> t;
cin >> u >> v;
for (int i=0; i<m; i++) {
int a, b, w;
cin >> a >> b >> w;
adj[a].push_back({b, w});
adj[b].push_back({a, w});
}
src(u);
for (int i=1; i<=n; i++) distu[i] = dist[i];
src(v);
for (int i=1; i<=n; i++) distv[i] = dist[i];
result = distu[v];
src(s);
for (int i=1; i<=n; i++) dists[i] = dist[i];
src(t);
for (int i=1; i<=n; i++) distt[i] = dist[i];
for (int i=1; i<=n; i++) {
if (dists[i] + distt[i] == dists[t]) {
access[i] = true;
}
}
go(s, t);
go(t, s);
cout << result << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void usaco()':
commuter_pass.cpp:18:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | freopen("problem.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:19:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | freopen("problem.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... |