Submission #1261007

#TimeUsernameProblemLanguageResultExecution timeMemory
1261007vominhhuy123관광 (NOI14_sightseeing)C++20
15 / 25
1957 ms98932 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; int n, m, k, visited[N], ans[N], p[N], sz[N]; vector<pair<int, int>> edge[N]; vector<int> adj[N]; int root(int u) { return p[u] != u ? p[u] = root(p[u]) : u; } void dfs(int u, int val) { visited[u] = 1; ans[u] = val; for (int v : adj[u]) if (!visited[v]) dfs(v, val); } 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); } scanf("%d %d %d", &n, &m, &k); fto(i, 1, n) p[i] = i, sz[i] = 1; fto(i, 1, m) { int u, v, w; scanf("%d %d %d", &u, &v, &w); edge[w].emplace_back(u, v); } fto(i, 1, n) ans[i] = -1; fdto(w, 100000, 0) { for (pair<int, int> p : edge[w]) { int u = p.first, v = p.second; if (join(u, v)) { adj[u].push_back(v); adj[v].push_back(u); } if (root(1) == root(u) && ans[u] == -1) dfs(u, w); if (root(1) == root(v) && ans[v] == -1) dfs(v, w); } } while (k--) { int x; scanf("%d", &x); printf("%d\n", ans[x]); } }

Compilation message (stderr)

sightseeing.cpp: In function 'int main()':
sightseeing.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d %d %d", &n, &m, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d %d %d", &u, &v, &w);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sightseeing.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...