# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
672938 | 2022-12-19T04:02:21 Z | vuavisao | Hotspot (NOI17_hotspot) | C++14 | 1 ms | 724 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); } dist[1] = 1; 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 - 1; 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 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 440 KB | Output is correct |
7 | Correct | 1 ms | 468 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 440 KB | Output is correct |
7 | Correct | 1 ms | 468 KB | Output is correct |
8 | Correct | 1 ms | 444 KB | Output is correct |
9 | Correct | 1 ms | 468 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 444 KB | Output is correct |
12 | Correct | 0 ms | 444 KB | Output is correct |
13 | Correct | 1 ms | 468 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 440 KB | Output is correct |
7 | Correct | 1 ms | 468 KB | Output is correct |
8 | Correct | 1 ms | 440 KB | Output is correct |
9 | Correct | 1 ms | 468 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 468 KB | Output is correct |
12 | Correct | 0 ms | 468 KB | Output is correct |
13 | Correct | 1 ms | 444 KB | Output is correct |
14 | Correct | 1 ms | 452 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 440 KB | Output is correct |
7 | Correct | 1 ms | 468 KB | Output is correct |
8 | Correct | 1 ms | 444 KB | Output is correct |
9 | Correct | 1 ms | 468 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 444 KB | Output is correct |
12 | Correct | 0 ms | 444 KB | Output is correct |
13 | Correct | 1 ms | 468 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
15 | Correct | 1 ms | 440 KB | Output is correct |
16 | Correct | 1 ms | 468 KB | Output is correct |
17 | Correct | 1 ms | 468 KB | Output is correct |
18 | Correct | 1 ms | 468 KB | Output is correct |
19 | Correct | 0 ms | 468 KB | Output is correct |
20 | Correct | 1 ms | 444 KB | Output is correct |
21 | Correct | 1 ms | 452 KB | Output is correct |
22 | Correct | 1 ms | 468 KB | Output is correct |
23 | Correct | 1 ms | 468 KB | Output is correct |
24 | Correct | 1 ms | 452 KB | Output is correct |
25 | Correct | 1 ms | 468 KB | Output is correct |
26 | Correct | 1 ms | 468 KB | Output is correct |
27 | Correct | 1 ms | 468 KB | Output is correct |
28 | Correct | 1 ms | 468 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 1 ms | 468 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 440 KB | Output is correct |
7 | Correct | 1 ms | 468 KB | Output is correct |
8 | Correct | 1 ms | 444 KB | Output is correct |
9 | Correct | 1 ms | 468 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 444 KB | Output is correct |
12 | Correct | 0 ms | 444 KB | Output is correct |
13 | Correct | 1 ms | 468 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
15 | Runtime error | 1 ms | 724 KB | Execution killed with signal 6 |
16 | 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 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 468 KB | Output is correct |
6 | Correct | 1 ms | 440 KB | Output is correct |
7 | Correct | 1 ms | 468 KB | Output is correct |
8 | Correct | 1 ms | 444 KB | Output is correct |
9 | Correct | 1 ms | 468 KB | Output is correct |
10 | Correct | 1 ms | 468 KB | Output is correct |
11 | Correct | 1 ms | 444 KB | Output is correct |
12 | Correct | 0 ms | 444 KB | Output is correct |
13 | Correct | 1 ms | 468 KB | Output is correct |
14 | Correct | 1 ms | 468 KB | Output is correct |
15 | Correct | 1 ms | 440 KB | Output is correct |
16 | Correct | 1 ms | 468 KB | Output is correct |
17 | Correct | 1 ms | 468 KB | Output is correct |
18 | Correct | 1 ms | 468 KB | Output is correct |
19 | Correct | 0 ms | 468 KB | Output is correct |
20 | Correct | 1 ms | 444 KB | Output is correct |
21 | Correct | 1 ms | 452 KB | Output is correct |
22 | Correct | 1 ms | 468 KB | Output is correct |
23 | Correct | 1 ms | 468 KB | Output is correct |
24 | Correct | 1 ms | 452 KB | Output is correct |
25 | Correct | 1 ms | 468 KB | Output is correct |
26 | Correct | 1 ms | 468 KB | Output is correct |
27 | Correct | 1 ms | 468 KB | Output is correct |
28 | Correct | 1 ms | 468 KB | Output is correct |
29 | Runtime error | 1 ms | 724 KB | Execution killed with signal 6 |
30 | Halted | 0 ms | 0 KB | - |