Submission #1095674

#TimeUsernameProblemLanguageResultExecution timeMemory
1095674vjudge1Railway (BOI17_railway)C++17
100 / 100
79 ms39888 KiB
#include<bits/stdc++.h> using namespace std; #define task "test" #define pb push_back #define fi first #define se second #define for1(i,j,k) for(int i=j;i<=k;i++) #define for2(i,j,k) for(int i=j;i>=k;i--) #define for3(i,j,k,l) for(int i=j;i<=k;i+=l) #define bit(n,i) ((n>>i)&1) #define all(x) x.begin(),x.end() //#pragma GCC optimize("O2,unroll-loops") //#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,ssse3,sse4,popcnt") #define int long long typedef long long ll; typedef pair<int,int> pii; typedef double ld; typedef pair<ld,ld> pdd; typedef pair<ll,ll> pll; const ll maxn=1e5+2; const ll inf=1e18; const ll mod=1e9+7; const ll base=311; int n,m,k,ans; vector<int> adj[maxn],res; int in[maxn],out[maxn],Time,par[maxn][20],sum[maxn]; void dfs(int u,int pre) { in[u]=++Time; par[u][0]=pre; for (int i=1;i<=17;i++) { par[u][i]=par[par[u][i-1]][i-1]; } for (int v: adj[u]) { if (v==pre) continue; dfs(v,u); } out[u]=Time; } inline bool is_ancestor(int u,int v) { return (in[u]<=in[v] && out[v]<=out[u]); } int lca(int u,int v) { if (is_ancestor(u,v)) return u; if (is_ancestor(v,u)) return v; for (int i=17;i>=0;i--) { if (!is_ancestor(par[u][i],v)) u=par[u][i]; } return par[u][0]; } int d[maxn],kkk[maxn]; void dfs1(int u,int pre) { for (int v:adj[u]) { if (v==pre) continue; dfs1(v, u); sum[u]+=sum[v]; } if (sum[u]>=k) { ans++; res.pb(kkk[u]); } //cout <<"ww "<< u<< ' '<<sum[u]<<'\n'; } vector<int> a[maxn]; pii ed[maxn]; void sol() { cin >> n>> m>> k; for (int i=1;i<n;i++) { int u,v;cin >> u>>v; adj[u].pb(v); adj[v].pb(u); ed[i]={u,v}; } dfs(1,1); for (int i=1;i<n;i++) { if (is_ancestor(ed[i].fi,ed[i].se)) { kkk[ed[i].se]=i; } else kkk[ed[i].fi]=i; } for (int i=1;i<=m;i++) { cin >> d[i]; for (int j=1;j<=d[i];j++) { int x;cin >> x; a[i].pb(x); sum[x]++; } sort(all(a[i]),[](int u,int v){ return in[u]< in[v]; }); int hi=a[i][d[i]-1]; for (int j=0;j<d[i]-1;j++) { hi=lca(hi,a[i][j]); sum[lca(a[i][j],a[i][j+1])]--; } sum[hi]--; } dfs1(1,1); cout << ans<<'\n'; sort(all(res)); for (int v: res) cout << v<<' '; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); if (fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } // int theta; cin >> theta; int t=1;//cin >> t; while (t--) sol(); }

Compilation message (stderr)

railway.cpp: In function 'int32_t main()':
railway.cpp:128:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  128 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
railway.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |         freopen(task".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...