제출 #280126

#제출 시각아이디문제언어결과실행 시간메모리
280126Haunted_CppHotspot (NOI17_hotspot)C++17
38 / 100
346 ms524292 KiB
/** * author: Haunted_Cpp **/ #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void debug_out() { cerr << endl; } template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__) #else #define debug(...) 47 #endif const int MAX_N = 1e3 + 5; const int MAX_K = 20 + 5; vector<vector<int>> dp(MAX_N, vector<int>(MAX_K, -1)); vector<vector<int>> g(MAX_N); vector<int> h(MAX_N), depth(MAX_N); vector<int> sum(MAX_N); void dfs(int node, int p) { dp[node][0] = p; for (auto to : g[node]) { if (to != p) { depth[to] = depth[node] + 1; dfs(to, node); } } } int kth(int node, int diff) { for (int i = MAX_K - 1; ~i; i--) { if ((diff >> i) & 1) { node = dp[node][i]; } } return node; } int lca(int u, int v) { if (depth[u] < depth[v]) swap(u, v); u = kth(u, depth[u] - depth[v]); if (u == v) return u; for (int i = MAX_K - 1; ~i; i--) { if (dp[u][i] != dp[v][i]) { u = dp[u][i]; v = dp[v][i]; } } return dp[u][0]; } int solve(int node, int p) { for (auto to : g[node]) { if (to != p) { sum[node] += solve(to, node); } } debug(node, sum[node]); return sum[node]; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int st, et; cin >> st >> et; g[st].emplace_back(et); g[et].emplace_back(st); } dfs(0, -1); for(int j = 1; j < MAX_K; j++) { for (int i = 0; i < n; i++) { if (~dp[i][j - 1]) { dp[i][j] = dp[dp[i][j - 1]][j - 1]; } } } int k; cin >> k; while(k--) { int st, et; cin >> st >> et; ++sum[st]; ++sum[et]; debug(st, et); int LCA = lca(st, et); if (LCA != -1) { sum[LCA] -= 1; } LCA = dp[LCA][0]; if (LCA != -1) { sum[LCA] -= 1; } } solve(0, -1); cout << (max_element(sum.begin(), sum.end()) - sum.begin()) << '\n'; return 0; }

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

hotspot.cpp: In function 'int solve(int, int)':
hotspot.cpp:22:20: warning: statement has no effect [-Wunused-value]
   22 | #define debug(...) 47
      |                    ^~
hotspot.cpp:72:3: note: in expansion of macro 'debug'
   72 |   debug(node, sum[node]);
      |   ^~~~~
hotspot.cpp: In function 'int main()':
hotspot.cpp:22:20: warning: statement has no effect [-Wunused-value]
   22 | #define debug(...) 47
      |                    ^~
hotspot.cpp:103:5: note: in expansion of macro 'debug'
  103 |     debug(st, et);
      |     ^~~~~
#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...