이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e18;
const ll blocksz = 320;
const ll N = 3e5+8;
ll d[N][4];
int n,m,s,t,x,y;
vpll g[N];
bool use[N];
void dijkstra(int s, int t){
for(int i = 1; i <= n; i++) d[i][t] = inf, use[i] = 0;
priority_queue<pll,vpll,greater<pll>> pq;
pq.push({0,s});
d[s][t] = 0;
while(pq.size()){
int u = pq.top().se;
ll dist = pq.top().fi;
pq.pop();
if(use[u]) continue;
use[u] = 1;
for(pll ed:g[u]){
int v = ed.fi, w = ed.se;
if(d[v][t] > d[u][t]+w){
d[v][t] = d[u][t]+w;
pq.push({d[v][t],v});
}
}
}
}
struct edge{
ll u,v,w;
};
vector<edge> ed;
vector<int> adj[N];
vector<int> topo;
int vst[N];
void tps(int u){
vst[u] = 1;
for(int v:adj[u]){
if(vst[v]) continue;
tps(v);
}
topo.pb(u);
vst[u] = 2;
}
ll dp[2][N];
void solve(){
cin >> n >> m >> s >> t >> x >> y;
for(int i = 1; i <= m; i++){
int u,v,w;cin >> u >> v >> w;
g[u].pb({v,w});
g[v].pb({u,w});
ed.pb({u,v,w});
}
dijkstra(s,0);
dijkstra(t,1);
dijkstra(x,2);
dijkstra(y,3);
for(edge e:ed){
int u = e.u, v = e.v;
ll w = e.w;
if(d[u][0]+w+d[v][1] == d[t][0]) adj[u].pb(v);
else if(d[v][0]+w+d[u][1] == d[t][0]) adj[v].pb(u);
}
tps(s);
for(int i = 1; i <= n; i++) dp[0][i] = dp[1][i] = inf;
for(int u:topo){
dp[0][u] = d[u][2];
dp[1][u] = d[u][3];
for(int v:adj[u]){
dp[0][u] = min(dp[0][u],dp[0][v]);
dp[1][u] = min(dp[1][u],dp[1][v]);
}
}
ll ans = d[y][2];
for(int i = 1; i <= n; i++) ans = min({ans,dp[0][i]+d[i][3],dp[1][i]+d[i][2]});
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("test.inp", "r")) {
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll T = 1;
// cin >> T;
for (ll i = 1; i <= T; i++) {
solve();
cout << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'void dijkstra(int, int)':
commuter_pass.cpp:31:12: warning: unused variable 'dist' [-Wunused-variable]
31 | ll dist = pq.top().fi;
| ^~~~
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen("test.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | freopen("test.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... |