제출 #495232

#제출 시각아이디문제언어결과실행 시간메모리
495232ZielEvacuation plan (IZhO18_plan)C++17
54 / 100
4054 ms237044 KiB
/** * LES GREATEABLES BRO TEAM **/ #include <bits/stdc++.h> using namespace std; using ll = long long; #define sz(x) (int)x.size() const bool FLAG = false; void setIO(const string &f = ""); signed main() { setIO(); int n, m; cin >> n >> m; vector<vector<pair<int, int>>> adj(n + 1); set<pair<int, int>> edges; for (int i = 0, x, y, z; i < m; i++) { cin >> x >> y >> z; adj[x].push_back({y, z}); adj[y].push_back({x, z}); edges.insert({min(x, y), max(x, y)}); } int k; cin >> k; vector<int> g(k + 1), d(n + 1, 1e9 + 17); set<int> npp; for (int i = 1; i <= k; i++) { cin >> g[i]; npp.insert(g[i]); } { set<pair<int, int>> q; for (int i = 1; i <= k; i++) { q.insert({0, g[i]}); d[g[i]] = 0; } while (sz(q)) { int v = q.begin()->second; q.erase(q.begin()); for (auto [to, len]: adj[v]) { if (d[to] > d[v] + len) { q.erase({d[to], to}); d[to] = d[v] + len; q.insert({d[to], to}); } } } } int qr; cin >> qr; map<int, int> dp[n + 1]; vector<bool> was(n + 1); while (qr--) { int s, t; cin >> s >> t; if (edges.count({min(s, t), max(s, t)})) { cout << min(d[s], d[t]) << '\n'; } else if (npp.count(s) || npp.count(t)) { cout << "0\n"; } else { if (was[s]) { if (dp[s].count(t)) cout << dp[s][t] << '\n'; else cout << d[t] << '\n'; } else if (was[t]) { if (dp[t].count(s)) cout << dp[t][s] << '\n'; else cout << d[s] << '\n'; } else { set<pair<int, int>> q; vector<int> d2(n + 1, 0); q.insert({d[s], s}); d2[s] = d[s]; while (sz(q)) { int v = q.begin()->second; q.erase(q.begin()); for(auto [to, len]: adj[v]) { int dd = min(d[to], d2[v]); if (d2[to] < dd) { q.erase({-d2[to], to}); d2[to] = dd; q.insert({-d2[to], to}); } } } cout << min(d2[s], d2[t]) << '\n'; was[s] = 1; for (int i = 1; i <= n; i++) { if (d2[i] != d[i]) dp[s][i] = d2[i]; } } } } return 0; } void setIO(const string &f) { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen((f + ".in").c_str(), "r")) { freopen((f + ".in").c_str(), "r", stdin); freopen((f + ".out").c_str(), "w", stdout); } }

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

plan.cpp: In function 'void setIO(const string&)':
plan.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
plan.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen((f + ".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...
#Verdict Execution timeMemoryGrader output
Fetching results...