제출 #638765

#제출 시각아이디문제언어결과실행 시간메모리
638765Ez0zIOVgTsSgTCommuter Pass (JOI18_commuter_pass)C++14
100 / 100
309 ms23324 KiB
#include<bits/stdc++.h> using namespace std; void DBG() { cerr << "]\n"; } template<class H, class... T> void DBG(H h, T... t) { cerr << h; if(sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef LOCAL #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif // LOCAL #define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--) #define R0F(i,a) ROF(i,0,a) #define each(e,a) for(auto &e : (a)) #define sz(v) (int)(v).size() #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define pb push_back #define tcT template<class T #define nl "\n" #define fi first #define se second using ll = long long; using vi = vector<int>; using pi = pair<int,int>; using str = string; tcT> using pqg = priority_queue<T,vector<T>,greater<T>>; void setIO(string NAME = "") { cin.tie(0)->sync_with_stdio(0); if(sz(NAME)) { freopen((NAME + ".inp").c_str(),"r",stdin); freopen((NAME + ".out").c_str(),"w",stdout); } } tcT> bool ckmin(T&a, const T&b) { return b < a ? a=b,1 : 0; } tcT> bool ckmax(T&a, const T&b) { return b > a ? a=b,1 : 0; } const int MOD = 1e9 + 7; const ll INF = 1e18; const int MX = 1e5+5; int N, M, S, T, U, V; vector<pi> adj[MX]; ll distS[MX], distT[MX], distU[MX], distV[MX], dp[MX]; ll ans = INF; void dijkstra(int src, ll dist[]) { FOR(i,1,N+1) dist[i] = INF; pqg<pair<ll,int>> pq; pq.push({dist[src] = 0, src}); while(!pq.empty()) { int u = pq.top().se; ll du = pq.top().fi; pq.pop(); if(du > dist[u]) continue; each(ed, adj[u]) { int v = ed.fi; ll dv = du + ed.se; if(ckmin(dist[v], dv)) pq.push({dist[v], v}); } } } void dfs(int u, bool fromT) { if(~dp[u]) return; if(distS[u] + distT[u] != distS[T]) { dp[u] = INF; return; } dp[u] = distV[u]; each(ed, adj[u]) { int v = ed.fi; if(fromT ? distT[u] + ed.se != distT[v] : distS[u] + ed.se != distS[v]) continue; dfs(v, fromT); ckmin(dp[u], dp[v]); } ckmin(ans, dp[u] + distU[u]); } void solve() { cin >> N >> M >> S >> T >> U >> V; F0R(i, M) { int u, v, w; cin >> u >> v >> w; adj[u].pb({v, w}); adj[v].pb({u, w}); } dijkstra(S, distS); dijkstra(T, distT); dijkstra(U, distU); dijkstra(V, distV); ans = distU[V]; memset(dp, -1, sizeof dp); dfs(S, 0); memset(dp, -1, sizeof dp); dfs(T, 1); cout << ans << nl; } int main() { setIO(); int t=1; //cin>>t; while(t-->0) { solve(); } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

commuter_pass.cpp: In function 'void setIO(std::string)':
commuter_pass.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen((NAME + ".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen((NAME + ".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...