제출 #1096334

#제출 시각아이디문제언어결과실행 시간메모리
1096334tachvoiRailway (BOI17_railway)C++14
36 / 100
136 ms52680 KiB
#include <bits/stdc++.h> using namespace std; #define N 200005 #define LOG 18 #define int long long int tin[N], depth[N], timer, par[N][LOG], dp[N], n, q, k; vector <int> adj[N], ans; map <pair <int, int>, int> lab; void dfs1(int u) { tin[u] = ++timer; for (int v : adj[u]) if (v != par[u][0]) par[v][0] = u, depth[v] = depth[u] + 1, dfs1(v); } int getlca(int u, int v) { if (depth[u] < depth[v]) swap(u, v); for (int k = LOG - 1; k >= 0; k--) if (par[u][k] && depth[par[u][k]] >= depth[v]) u = par[u][k]; if (u == v) return u; for (int k = LOG - 1; k >= 0; k--) if (par[u][k] != par[v][k]) { u = par[u][k]; v = par[v][k]; } return par[u][0]; } void dfs2(int u) { for (int v : adj[u]) if (v != par[u][0]) dfs2(v), dp[u] += dp[v]; if (dp[u] >= 2 * k) ans.push_back(lab[{u, par[u][0]}]); } bool cmp(int &x, int &y) { return tin[x] < tin[y]; } signed main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cin >> n >> q >> k; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); lab[{u, v}] = lab[{v, u}] = i; } dfs1(1); for (int k = 1; k < LOG; k++) for (int u = 1; u <= n; u++) par[u][k] = par[par[u][k - 1]][k - 1]; while (q--) { int m; cin >> m; set <int> vec; vector <int> d; for (int i = 1; i <= m; i++) { int x; cin >> x; vec.insert(x); } for (int x : vec) d.push_back(x); sort(d.begin(), d.end()); d.push_back(d[0]); for (int i = 1; i < d.size(); i++) { int u = d[i - 1], v = d[i]; int lca = getlca(u, v); dp[u]++; dp[v]++; dp[lca] -= 2; } } dfs2(1); sort(ans.begin(), ans.end()); cout << ans.size() << '\n'; for (int x : ans) cout << x << ' '; }

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

railway.cpp: In function 'int main()':
railway.cpp:81:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for (int i = 1; i < d.size(); i++)
      |                         ~~^~~~~~~~~~
#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...