Submission #311690

#TimeUsernameProblemLanguageResultExecution timeMemory
311690BeanZRailway (BOI17_railway)C++14
100 / 100
279 ms54796 KiB
// I_Love_LPL #include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int N = 1e5 + 5; const int lg = 17; vector<pair<ll, ll>> node[N]; vector<ll> fuckoff[N]; vector<ll> ans; ll dep[N], dp[N][18], up[N]; set<ll> st[N]; ll k; ll LCA(ll u, ll v){ if (dep[u] > dep[v]) swap(u, v); ll dis = dep[v] - dep[u]; for (int i = lg; i >= 0; i--){ if (dis & (1 << i)){ v = dp[v][i]; } } if (u == v) return u; for (int i = lg; i >= 0; i--){ if (dp[u][i] != dp[v][i]){ v = dp[v][i]; u = dp[u][i]; } } return dp[u][0]; } void dfs2(ll u, ll p){ for (auto j : node[u]){ if (j.first == p) continue; dfs2(j.first, u); if (st[u].size() < st[j.first].size()) swap(st[u], st[j.first]); st[u].insert(st[j.first].begin(), st[j.first].end()); } for (auto j : fuckoff[u]) st[u].erase(j); if (st[u].size() >= k) ans.push_back(up[u]); } void dfs(ll u, ll p){ for (int i = 1; i <= lg; i++) dp[u][i] = dp[dp[u][i - 1]][i - 1]; for (auto j : node[u]){ if (j.first == p) continue; dp[j.first][0] = u; dep[j.first] = dep[u] + 1; up[j.first] = j.second; dfs(j.first, u); } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("A.inp", "r")){ freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n, m; cin >> n >> m >> k; for (int i = 1; i < n; i++){ ll u, v; cin >> u >> v; node[u].push_back({v, i}); node[v].push_back({u, i}); } dfs(1, 1); for (int tc = 1; tc <= m; tc++){ ll s, lca; cin >> s >> lca; st[lca].insert(tc); for (int i = 1; i < s; i++){ ll u; cin >> u; lca = LCA(lca, u); st[u].insert(tc); } fuckoff[lca].push_back(tc); } dfs2(1, 1); sort(ans.begin(), ans.end()); cout << ans.size() << endl; for (auto j : ans) cout << j << " "; } /* */

Compilation message (stderr)

railway.cpp: In function 'void dfs2(long long int, long long int)':
railway.cpp:40:22: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   40 |     if (st[u].size() >= k) ans.push_back(up[u]);
      |         ~~~~~~~~~~~~~^~~~
railway.cpp: In function 'int main()':
railway.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("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   57 |         freopen("test.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...