제출 #1312767

#제출 시각아이디문제언어결과실행 시간메모리
1312767nguyengiabach1201관광 (NOI14_sightseeing)C++20
15 / 25
2583 ms306376 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define el '\n' #define FNAME "" #define ll long long #define MOD (int)(1e9 + 7) #define INF (ll)(2e18 + 1) void setup() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen(FNAME ".inp", "r")) { freopen(FNAME ".inp", "r", stdin); freopen(FNAME ".out", "w", stdout); } } const int N = 5e5 + 5; int n, m, q; struct Edge { int to; ll weight; }; vector<Edge> adj[N]; ll ans[N]; int p[N]; bool checked[N]; struct State { int u; ll val; bool operator<(const State &other) const { return val < other.val; } }; void dijkstra() { for (int i = 1; i <= n; ++i) { ans[i] = -1; checked[i] = false; } priority_queue<State> pq; pq.push({1, INF}); ans[1] = INF; while (!pq.empty()) { int u = pq.top().u; ll val = pq.top().val; pq.pop(); if (checked[u]) continue; checked[u] = true; for (auto &e : adj[u]) { int v = e.to; ll w = e.weight; if (!checked[v]) { ll next_val = min(val, w); if (next_val > ans[v]) { ans[v] = next_val; pq.push({v, ans[v]}); } } } } } void solve() { cin >> n >> m >> q; for (int i = 0; i < m; ++i) { int x, y; ll z; cin >> x >> y >> z; adj[x].push_back({y, z}); adj[y].push_back({x, z}); } for (int i = 1; i <= q; ++i) cin >> p[i]; dijkstra(); for (int i = 1; i <= q; ++i) { if (ans[p[i]] == -1) cout << 0 << el; else cout << ans[p[i]] << el; } } int main() { setup(); solve(); return 0; }

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

sightseeing.cpp: In function 'void setup()':
sightseeing.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(FNAME ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.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(FNAME ".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...