# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
38883 | 2018-01-07T14:22:18 Z | cheater2k | Sightseeing (NOI14_sightseeing) | C++14 | 2566 ms | 165184 KB |
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n, m, q; int dsu[N]; vector< pair<int, pair<int,int> > > edges; vector< pair<int,int> > G[N]; int mn[N]; int anc(int p) { return p == dsu[p] ? p : dsu[p] = anc(dsu[p]); } void join(int p, int q) { p = anc(p); q = anc(q); dsu[p] = q; } inline void dfs(int u, int p) { for (int i = 0; i < G[u].size(); ++i) { int v = G[u][i].second, w = G[u][i].first; if (v == p) continue; mn[v] = min(mn[u], w); dfs(v, u); } } int main() { scanf("%d %d %d", &n, &m, &q); for (int i = 0; i < m; ++i) { int u, v, w; scanf("%d %d %d", &u, &v, &w); edges.push_back(make_pair(w, make_pair(u, v))); // w <= 1e5 } // build maximum spanning tree for (int i = 1; i <= n; ++i) dsu[i] = i; sort(edges.begin(), edges.end()); for (int i = m - 1; i >= 0; --i) { int w = edges[i].first; int u = edges[i].second.first; int v = edges[i].second.second; if (anc(u) == anc(v)) continue; join(u, v); G[u].push_back(make_pair(w, v)); G[v].push_back(make_pair(w, u)); } mn[1] = 1e9; dfs(1, 0); // answer queries while(q--) { int u; scanf("%d", &u); printf("%d\n", mn[u]); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 17644 KB | Output is correct |
2 | Correct | 3 ms | 17644 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 17816 KB | Output is correct |
2 | Correct | 6 ms | 17644 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 19680 KB | Output is correct |
2 | Correct | 36 ms | 19680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2566 ms | 91456 KB | Output is correct |
2 | Runtime error | 2513 ms | 165184 KB | Execution timed out (wall clock limit exceeded) |