제출 #632723

#제출 시각아이디문제언어결과실행 시간메모리
632723AlmaCommuter Pass (JOI18_commuter_pass)C++17
0 / 100
212 ms28480 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fi first #define se second using ll = long long; using ii = pair<int,int>; const int INF = 1e9; const ll LLINF = 1e18; using vi = vector<int>; using vvi = vector<vi>; void setIO (string fileName) { ios::sync_with_stdio(false); cin.tie(NULL); if (fileName != "std") { freopen((fileName + ".in").c_str(), "r", stdin); freopen((fileName + ".out").c_str(), "w", stdout); } } int dist; vi vis; set<ii> st; stack<int> stck; vector<vector<ii>> adj; int dfs (int u, int t) { if (u == t) return 0; vis[u] = true; int ret = INF; for (ii p: adj[u]) { int v = p.fi, c = p.se; if (!vis[v]) ret = min(ret, c + dfs(v, t)); } return ret; } void dfs2 (int u, int t, int d) { if (u == t and d == dist) { int a = u; while (stck.size()) { int b = stck.top(); stck.pop(); st.insert({a, b}); a = b; } } vis[u] = true; stck.push(u); for (ii p: adj[u]) { int v = p.fi, c = p.se; if (!vis[v]) dfs2(v, t, d + c); } stck.pop(); } int dijkstra (int n, int s, int t) { vi d(n, LLINF); d[s] = 0; priority_queue<ii> pq; pq.push({0, s}); while (pq.size()) { int u = pq.top().second; int di = -pq.top().first; pq.pop(); if (di > d[u]) continue; for (ii p: adj[u]) { int v = p.fi, c = p.se; if (di + c < d[v]) { d[v] = di+c; pq.push({-di-c, v}); } } } return d[t]; } signed main() { setIO("std"); int n, m, s, t, u, v, a, b, c; cin >> n >> m >> s >> t >> u >> v; adj = vector<vector<ii>>(n); s--; t--; u--; v--; while (m--) { cin >> a >> b >> c; a--; b--; adj[a].push_back({b, c}); adj[b].push_back({a, c}); } vis = vi(n, false); dist = dfs(s, t); vis = vi(n, false); dfs2(s, t, 0); for (int i = 0; i < n; i++) { // cout << i+1 << ": "; for (int j = 0; j < (int)adj[i].size(); j++) { int k = adj[i][j].fi; if (st.find({i, k}) != st.end() or st.find({k, i}) != st.end()) { adj[i][j].se = 0; } // cout << adj[i][j].fi+1 << ' ' << adj[i][j].se << ", "; } // cout << '\n'; } cout << dijkstra(n, u, v) << '\n'; return 0; }

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

commuter_pass.cpp: In function 'void setIO(std::string)':
commuter_pass.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen((fileName + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
commuter_pass.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen((fileName + ".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...