Submission #633181

#TimeUsernameProblemLanguageResultExecution timeMemory
633181AlmaValley (BOI19_valley)C++17
36 / 100
3097 ms9816 KiB
#include <bits/stdc++.h> using namespace std; #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); } } struct edge { int a, b, c; }; vector<ll> dijkstra (int n, int s, vector<vector<ii>>& adj) { vector<ll> dist(n, LLINF); dist[s] = 0; priority_queue<pair<ll, int>> pq; pq.push({0, s}); while (!pq.empty()) { int u = pq.top().second; ll d = -pq.top().first; pq.pop(); if (d > dist[u]) continue; for (ii p: adj[u]) { int v = p.fi, c = p.se; if (d + c < dist[v]) { dist[v] = d+c; pq.push({-d-c, v}); } } } return dist; } int main() { setIO("std"); int n, s, q, e; cin >> n >> s >> q >> e; e--; vector<edge> list(n-1); for (int i = 0; i < n-1; i++) { cin >> list[i].a >> list[i].b >> list[i].c; list[i].a--; list[i].b--; } int x, y; vector<bool> shop(n, false); for (int i = 0; i < s; i++) { cin >> x; shop[x-1] = true; } while (q--) { cin >> x >> y; x--; y--; vector<vector<ii>> adj(n); for (int i = 0; i < n-1; i++) { if (i == x) continue; adj[list[i].a].push_back({list[i].b, list[i].c}); adj[list[i].b].push_back({list[i].a, list[i].c}); } vector<ll> dist = dijkstra(n, y, adj); if (dist[e] != LLINF) { cout << "escaped\n"; } else { ll ans = LLINF; for (int i = 0; i < n; i++) { if (shop[i] and dist[i] != LLINF) { ans = min(ans, dist[i]); } } if (ans == LLINF) cout << "oo\n"; else cout << ans << '\n'; } } return 0; }

Compilation message (stderr)

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