제출 #672929

#제출 시각아이디문제언어결과실행 시간메모리
672929vuavisaoHotspot (NOI17_hotspot)C++14
0 / 100
1 ms468 KiB
#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

컴파일 시 표준 에러 (stderr) 메시지

hotspot.cpp: In function 'int32_t main()':
hotspot.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen("NOI17_hotspot.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hotspot.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen("NOI17_hotspot.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...