Submission #1261025

#TimeUsernameProblemLanguageResultExecution timeMemory
1261025vominhhuy123관광 (NOI14_sightseeing)C++20
25 / 25
1193 ms114572 KiB
#include <bits/stdc++.h> #define fto(i, a, b) for (int i = (a); i <= (b); ++i) #define fdto(i, b, a) for (int i = (b); i >= (a); --i) #define N 500005 #define mod 1000000007 using namespace std; struct Edge { int u, v, w; }; int n, m, k, ans[N], p[N], sz[N]; vector<pair<int, int>> adj[N]; vector<Edge> edge; int root(int u) { return p[u] != u ? p[u] = root(p[u]) : u; } bool join(int u, int v) { u = root(u), v = root(v); if (u == v) return false; if (sz[v] > sz[u]) swap(u, v); sz[u] += sz[v]; p[v] = u; return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } cin >> n >> m >> k; fto(i, 1, n) p[i] = i, sz[i] = 1; fto(i, 1, m) { int u, v, w; cin >> u >> v >> w; edge.push_back({u, v, w}); } sort(edge.begin(), edge.end(), [](Edge x, Edge y){ return x.w > y.w; }); for (Edge &p : edge) { int u = p.u, v = p.v, w = p.w; if (join(u, v)) { adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } } fto(i, 1, n) ans[i] = -1; queue<int> q; q.push(1); ans[1] = N+1; while (q.size()) { int u = q.front(); q.pop(); for (pair<int, int> &p : adj[u]) if (ans[p.first] == -1) { ans[p.first] = min(ans[u], p.second); q.push(p.first); } } while (k--) { int x; cin >> x; cout << ans[x] << '\n'; } }

Compilation message (stderr)

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