#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5;
const string NAME = "";
int n,m,S,T,X,Y,x,y,z;
ll distX[MAXN],distY[MAXN],dist[MAXN],rs,pre[MAXN];
vector<pair<int,int>> adj[MAXN];
vector<int> g[MAXN],grev[MAXN],topo;
bool vis[MAXN];
void dijkstra(int u, ll dist[]){
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
dist[u]=0, pq.ins(0,u);
while(!pq.empty()){
pair<ll,int> top = pq.top();
pq.pop();
if(top.fi>dist[top.se]) continue;
for(pair<int,int> p : adj[top.se])
if(top.fi+p.se<dist[p.fi]) dist[p.fi]=top.fi+p.se, pq.ins(dist[p.fi],p.fi);
}
}
void build(int u){
vis[u]=1;
for(pair<int,int> p : adj[u])
if(dist[u]-p.se==dist[p.fi]) g[p.fi].pb(u), grev[u].pb(p.fi);
for(pair<int,int> p : adj[u])
if(dist[u]-p.se==dist[p.fi]&&!vis[p.fi]) build(p.fi);
}
void dfs(int u, vector<int> (&g)[MAXN]){
vis[u]=1;
for(int v : g[u])
if(!vis[v]) dfs(v,g);
topo.pb(u);
}
void calc(int u, vector<int> (&g)[MAXN]){
memset(vis,0,sizeof(vis));
memset(pre,0x3f,sizeof(pre));
topo.clear(), dfs(u,g), reverse(topo.begin(),topo.end());
for(int i = 0; i<sz(topo); ++i){
rs=min(rs,distX[topo[i]]+pre[topo[i]]);
pre[topo[i]]=min(pre[topo[i]],distY[topo[i]]);
for(int j : g[topo[i]])
pre[j]=min(pre[j],pre[topo[i]]);
}
}
int main()
{
tt;
if(fopen((NAME + ".INP").c_str(), "r")) fo;
cin >> n >> m;
cin >> S >> T >> X >> Y;
for(int i = 1; i<=m; ++i)
cin >> x >> y >> z, adj[x].pb(y,z), adj[y].pb(x,z);
memset(distX,0x3f,sizeof(distX)), memset(distY,0x3f,sizeof(distY));
dijkstra(X,distX), dijkstra(Y,distY);
memset(dist,0x3f,sizeof(dist)), dijkstra(S,dist);
rs=distX[Y], build(T);
calc(S,g), calc(T,grev);
cout << rs;
}
컴파일 시 표준 에러 (stderr) 메시지
commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:64:45: note: in expansion of macro 'fo'
64 | if(fopen((NAME + ".INP").c_str(), "r")) fo;
| ^~
commuter_pass.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:64:45: note: in expansion of macro 'fo'
64 | if(fopen((NAME + ".INP").c_str(), "r")) fo;
| ^~
# | 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... |