제출 #1087604

#제출 시각아이디문제언어결과실행 시간메모리
1087604shiori_chanCommuter Pass (JOI18_commuter_pass)C++14
31 / 100
231 ms42924 KiB
#include<bits/stdc++.h> #define fi first #define se second using namespace std; using ll = long long; const int N = 4e5+5; const ll inf = 1e15; struct Edge{ int u,v; ll w; }; int n, m, X, Y, S, T; ll d[4][N], dp[2][N]; bool vis[N]; vector<int> adj[N], topo; vector<pair<int,ll>> g[N]; Edge E[N]; void Dijkstra(int source, int type) { priority_queue<pair<ll,int>> pq; for(int i = 1; i <= n; i++){ d[type][i] = inf; } d[type][source] = 0; pq.push({0, source}); while(!pq.empty()){ pair<ll,int> t = pq.top(); pq.pop(); if(t.fi > d[type][t.se]) continue; int x = t.se; for(pair<int,ll> e : g[x]){ int v = e.fi; ll w = e.se; if(d[type][v] > d[type][x] + w){ d[type][v] = d[type][x] + w; pq.push({-d[type][v], v}); } } } return; } void get_topoOrder(int x){ vis[x] = true; dp[0][x] = inf; dp[1][x] = inf; for(int v : adj[x]){ if(vis[v]) continue; get_topoOrder(v); } topo.push_back(x); return; } void solve() { cin >> n >> m; cin >> S >> T >> X >> Y; for(int i = 1; i <= m; i++){ int u,v; ll w; cin >> u >> v >> w; g[u].push_back(make_pair(v, w)); g[v].push_back(make_pair(u, w)); E[i] = {u, v, w}; } Dijkstra(S, 0); Dijkstra(T, 1); Dijkstra(X, 2); Dijkstra(Y, 3); for(int i = 1; i <= m; i++){ int u = E[i].u, v = E[i].v; if(d[0][u] + E[i].w + d[1][v] == d[0][T] || d[1][u] + E[i].w + d[0][v] == d[0][T]){ adj[u].push_back(v); adj[v].push_back(u); } } get_topoOrder(S); ll answer = d[2][Y]; for(int v : topo){ dp[0][v] = min(dp[0][v], d[2][v]); dp[1][v] = min(dp[1][v], d[3][v]); for(int x : adj[v]){ dp[0][x] = min(dp[0][x], dp[0][v]); dp[1][x] = min(dp[1][x], dp[1][v]); } answer = min(answer, dp[0][v] + dp[1][v]); } cout << answer <<"\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "task" if(fopen(name".INP", "r")){ freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout); } int t = 1; //cin >> t; while(t--){ solve(); } return 0; }

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

commuter_pass.cpp: In function 'int main()':
commuter_pass.cpp:110:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:111:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |         freopen(name".OUT", "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...