이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100005
#define MAXM 100005
#define mix(a, b) a = min(a,b)
using ll = long long;
const ll mod = 1e9 + 7;
vector<pair<int, ll>> g[MAXN];
vector<pair<int, ll>> gc[MAXN];
void dijkstra(vector<ll> &dist, int s) {
dist[s] = 0;
set<pair<ll, int>> q;
q.insert({0, s});
while (!q.empty()) {
int v = q.begin()->second;
q.erase(q.begin());
for (auto[u, c] : g[v]) {
if (dist[v] + c < dist[u]) {
q.erase({dist[u], u});
dist[u] = dist[v] + c;
q.insert({dist[u], u});
}
}
}
}
void solve() {
int n, m;
cin >> n >> m;
int s, t;
cin >> s >> t;
int u, v;
cin >> u >> v;
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
g[a].emplace_back(b, c);
g[b].emplace_back(a, c);
gc[a].emplace_back(b, c);
gc[b].emplace_back(a, c);
}
vector<ll> ds(n + 1, 1e18), dt(n + 1, 1e18);
dijkstra(ds, s);
dijkstra(dt, t);
ll dist = ds[t];
for (int w = 1; w <= n; w++) {
for (int i = 0; i < g[w].size(); i++) {
int to = g[w][i].first;
ll c = g[w][i].second;
if (ds[w] < ds[to]) {
if (ds[w] + c + dt[to] == dist)
g[w][i].second = 0;
}
}
}
vector<ll> bebra(n + 1, 1e18);
dijkstra(bebra, u);
ll ans = bebra[v];
// for (int w = 1; w <= n; w++) {
// for (int i = 0; i < g[w].size(); i++) {
// int to = g[w][i].first;
// ll c = g[w][i].second;
// if (dt[w] < dt[to]) {
// if (dt[w] + c + ds[to] == dist)
// g[w][i].second = 0;
// } else
// g[w][i].second = gc[w][i].second;
// }
// }
bebra.assign(n + 1, 1e18);
dijkstra(bebra, v);
cout << min(bebra[u],ans);
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void solve()':
commuter_pass.cpp:52:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < g[w].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... |