Submission #1004211

#TimeUsernameProblemLanguageResultExecution timeMemory
1004211vjudge1Railway (BOI17_railway)C++17
0 / 100
1067 ms417616 KiB
#pragma GCC optimize("-O3") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define vl vector<ll> #define vi vector<int> #define pii pair<int, int> #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define pb push_back #define p_b pop_back #define f first #define s second using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const ll sz = 1e5+5; vl g[sz]; set<ll>st[sz]; ll vis[sz], p[30][sz], lev[sz], par[sz]; void dfs(ll node) { vis[node] = 1; for(auto u : g[node]) { if(vis[u]) continue; p[0][u] = node; par[u] = node; lev[u] = lev[node] + 1; dfs(u); } } ll jump(ll x, ll k) { for(ll i = 0; i < 27; i++) { if((k >> i) & 1) x = p[i][x]; } return x; } ll lca(ll x, ll y) { if(lev[x] > lev[y]) swap(x, y); ll d = lev[y] - lev[x]; y = jump(y, d); if(x == y) return x; else { for(ll i = 26; i >= 0; i--) { if(p[i][x] != p[i][y]) { x = p[i][x]; y = p[i][y]; } } return p[0][x]; } } void solve() { ll n, m, tk, i, j, l; cin >> n >> m >> tk; map<pll, ll>mp; for(ll i = 1; i <= n - 1; i++) { ll x, y; cin >> x >> y; g[x].pb(y); g[y].pb(x); mp[{x, y}] = i; mp[{y, x}] = i; } dfs(1); for(i = 1; i < 27; i++) { for(j = 1; j <= n; j++) p[i][j] = p[i-1][p[i-1][j]]; } for(i = 1; i <= m; i++) { ll k; cin >> k; vl vect; vect.pb(0); for(j = 1; j <= k; j++){ ll x; cin >> x; vect.pb(x); } for(j = 1; j <= k; j++){ for(l = j + 1; l <= k; l++){ ll a = lca(vect[j], vect[l]); ll x = vect[j], y = vect[l]; while(x != a) { st[mp[{x, par[x]}]].insert(i); x = par[x]; } while(y != a) { st[mp[{y, par[y]}]].insert(i); y = par[y]; } } } } vl f; for(i = 1; i <= n - 1; i++) { if(st[i].size() >= tk) f.pb(i); } cout << f.size() << "\n"; for(auto u : f) cout << u << ' '; cout << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll tests = 1; //cin >> tests; while(tests--) { solve(); } }

Compilation message (stderr)

railway.cpp: In function 'void solve()':
railway.cpp:118:25: 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]
  118 |         if(st[i].size() >= tk)
      |            ~~~~~~~~~~~~~^~~~~
#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...