Submission #95163

#TimeUsernameProblemLanguageResultExecution timeMemory
95163karmaSightseeing (NOI14_sightseeing)C++11
25 / 25
1765 ms211800 KiB
#include<bits/stdc++.h> #define For(i, a, b) for(int i = a, _b = b; i <= _b; ++i) #define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i) #define FileName "test" #define ll long long #define ld long double #define ull unsigned long long #define Print(x) cerr << #x << "is " << x << '\n'; #define pb push_back #define x first #define y second //#define Karma using namespace std; template<typename T> inline void Cin(T &x) { char c; T sign = 1; x = 0; for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') sign = -1; for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sign; } template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');} template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);} template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);} template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);} typedef pair<int, pair<int, int>> TEdge; const int N = 1e6 + 7; vector<TEdge> e; int n, m, q, res[N], lab[N]; vector<int> a[N]; int Find(int u) { return lab[u] < 0? u: lab[u] = Find(lab[u]); } void Union(int r, int s) { if(lab[r] > lab[s]) swap(r, s); lab[r] += lab[s], lab[s] = r; } void DFS(int u, int par) { for(int i: a[u]) { int v = e[i].y.x ^ e[i].y.y ^ u; if(v == par) continue; res[v] = min(res[u], e[i].x); DFS(v, u); } } void Enter() { Cin(n, m, q); memset(&lab, -1, sizeof lab); e.resize(m); for(int i = 0; i < m; ++i) { int u, v, w; Cin(u, v, w); e[i] = {w, {u, v}}; } sort(e.begin(), e.end(), greater<TEdge>()); for(int i = 0; i < m; ++ i) { int u = e[i].y.x, v = e[i].y.y, w = e[i].x; int r = Find(u), s = Find(v); if(r != s) { Union(r, s); a[u].pb(i), a[v].pb(i); } } res[1] = int(1e9) + 7; DFS(1, 1); } void Solve() { while(q --) { int x; Cin(x); Cout(res[x], '\n'); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef Karma freopen(FileName".inp", "r", stdin); freopen(FileName".out", "w", stdout); #endif // Karma Enter(); Solve(); return 0; }

Compilation message (stderr)

sightseeing.cpp: In function 'void Enter()':
sightseeing.cpp:72:41: warning: unused variable 'w' [-Wunused-variable]
         int u = e[i].y.x, v = e[i].y.y, w = e[i].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...