이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) __builtin_popcountll(a)
#define bithigh(a) 63-__builtin_clzll(a)
#define lg bithigh
ll highpow(ll a) { return 1LL << (ll)lg(a); }
using namespace std;
const ll LINF = 4e18;
const int mxN = 2e5+10, INF = 2e9, mod = (1 ? 1e9+7 : 998244353);
ll n, m, S, T, U, V, dp[mxN], dist[3][mxN], indeg[mxN];
vector<array<ll, 2> > g[mxN];
vector<int> b[mxN], dag[mxN], topo;
void Dijkstra(int S, ll* dist){
priority_queue<array<ll, 2>,
vector<array<ll, 2> >,
greater<array<ll, 2> > > pq;
for (int i = 0; i < n; i++) dist[i] = LINF;
dist[S] = 0;
pq.push({0, S});
while (pq.size()){
auto [d, s] = pq.top(); pq.pop();
if (d > dist[s]) continue;
for (auto [u, w] : g[s]){
if (d + w < dist[u]){
dist[u] = d + w;
pq.push({d+w, u});
}
}
}
}
void dfs(int s){
indeg[s] = 0;
for (int u : b[s]){
dag[u].pb(s);
indeg[s]++;
if (!~indeg[u]) dfs(u);
}
}
ll DP(){
for (int s = 0; s < n; s++) dp[s] = LINF;
ll ans = LINF;
for (int s : topo){
dp[s] = dist[0][s];
for (int u : dag[s]) smin(dp[s], dp[u]);
smin(ans, dp[s] + dist[1][s]);
}
return ans;
}
void Solve(){
cin >> n >> m >> S >> T >> U >> V;
S--; T--; U--; V--;
for (int i = 0; i < m; i++){
ri(u); ri(v); rl(w);
u--; v--;
g[u].pb({v, w});
g[v].pb({u, w});
}
Dijkstra(U, dist[0]);
Dijkstra(V, dist[1]);
Dijkstra(S, dist[2]);
for (int s = 0; s < n; s++)
for (auto [u, w] : g[s])
if (dist[2][s] + w == dist[2][u])
b[u].pb(s);
memset(indeg, -1, sizeof(indeg));
dfs(T);
queue<int> q;
for (int s = 0; s < n; s++)
if (!indeg[s])
q.push(s);
while (q.size()){
int s = q.front(); q.pop();
topo.pb(s);
for (int u : dag[s]){
indeg[u]--;
if (!indeg[u]) q.push(u);
}
}
reverse(all(topo));
ll ans = dist[0][V];
smin(ans, DP());
swap(dist[0], dist[1]);
smin(ans, DP());
cout << ans << en;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0); cerr.tie(0);
cout << setprecision(12) << fixed;
cerr << setprecision(12) << fixed;
cerr << "Started!" << endl;
int t = 1;
//cin >> t;
while (t--)
Solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'long long int highpow(long long int)':
commuter_pass.cpp:26:22: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
26 | #define bithigh(a) 63-__builtin_clzll(a)
| ^
commuter_pass.cpp:27:12: note: in expansion of macro 'bithigh'
27 | #define lg bithigh
| ^~~~~~~
commuter_pass.cpp:28:38: note: in expansion of macro 'lg'
28 | ll highpow(ll a) { return 1LL << (ll)lg(a); }
| ^~
# | 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... |