# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
672929 | 2022-12-19T03:42:44 Z | vuavisao | Hotspot (NOI17_hotspot) | C++14 | 1 ms | 468 KB |
#include<bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define ll long long using namespace std; const int N = 5e3 + 10; int n, m, q; vector<int> g[N]; int Lg, dist[N], parent[20][N]; int f[N]; void dfs(int u); void dfs(int u) { for(const auto& v : g[u]) { if(v == parent[0][u]) continue; dist[v] = dist[u] + 1; parent[0][v] = u; dfs(v); } } int lca(int u, int v); int lca(int u, int v) { if(dist[u] < dist[v]) swap(u, v); int delta = dist[u] - dist[v]; for(int i = Lg; i >= 0; -- i) { if(delta >> i & 1) u = parent[i][u]; } if(u == v) return u; for(int i = Lg; i >= 0; -- i) { if(parent[i][u] == parent[i][v]) continue; u = parent[i][u]; v = parent[i][v]; } return parent[0][u]; } void dfs_finally(int u); void dfs_finally(int u) { for(const auto& v : g[u]) { if(v == parent[0][u]) continue; dfs_finally(v); f[u] += f[v]; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("NOI17_hotspot.inp", "r")) { freopen("NOI17_hotspot.inp", "r", stdin); freopen("NOI17_hotspot.out", "w", stdout); } cin >> n >> m; if(m != n - 1) assert(false); for(int i = 2; i <= n; ++ i) { int u, v; cin >> u >> v; ++ u; ++ v; g[u].push_back(v); g[v].push_back(u); } dfs(1); Lg = __lg(n); for(int j = 1; j <= Lg; ++ j) { for(int i = 1; i <= n; ++ i) { parent[j][i] = parent[j - 1][parent[j - 1][i]]; } } cin >> q; while(q-- > 0) { int u, v; cin >> u >> v; ++ u; ++ v; int anc = lca(u, v); ++ f[u]; ++ f[v]; -- f[anc]; -- f[parent[0][anc]]; } dfs_finally(1); cout << max_element(f + 1, f + 1 + n) - f; return 0; } /// Code by vuavisao
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Incorrect | 1 ms | 448 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Incorrect | 1 ms | 448 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Incorrect | 1 ms | 448 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Incorrect | 1 ms | 448 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Incorrect | 1 ms | 448 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Incorrect | 1 ms | 448 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |