Submission #1115235

#TimeUsernameProblemLanguageResultExecution timeMemory
1115235PieArmyRailway (BOI17_railway)C++17
100 / 100
85 ms24512 KiB
typedef long long ll; ll pie(ll army){return (1ll<<army);} #include <bits/stdc++.h> #define fr first #define sc second #define pb push_back #define endl '\n' #define mid ((left+right)>>1) const ll inf=2000000000000000005; const int sonsuz=2000000005; using namespace std; ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;} int n,m,k; int tim=0; int dep[100001],par[100001][17],val[100001],loc[100001]; vector<pair<int,int>>komsu[100001]; vector<int>ans; void dfs1(int pos){ for(int i=1;i<17;i++){ par[pos][i]=par[par[pos][i-1]][i-1]; } loc[pos]=tim++; for(auto x:komsu[pos]){ if(par[pos][0]==x.fr)continue; dep[x.fr]=dep[pos]+1; par[x.fr][0]=pos; dfs1(x.fr); } } void dfs2(int pos,int ed){ for(auto x:komsu[pos]){ if(par[pos][0]==x.fr)continue; dfs2(x.fr,x.sc); val[pos]+=val[x.fr]; } if(val[pos]>=k)ans.pb(ed); } int lca(int a,int b){ if(dep[a]<dep[b])swap(a,b); for(int i=0;i<17;i++){ if((dep[a]-dep[b])&pie(i)){ a=par[a][i]; } } if(a!=b){ for(int i=17-1;i>=0;i--){ if(par[a][i]!=par[b][i]){ a=par[a][i]; b=par[b][i]; } } a=par[a][0]; } return a; } void code(){ cin>>n>>m>>k; for(int i=1;i<n;i++){ int x,y;cin>>x>>y; komsu[x].pb({y,i}); komsu[y].pb({x,i}); } dfs1(1); for(int i=1;i<=m;i++){ int s;cin>>s; vector<int>v; for(int j=0;j<s;j++){ int x;cin>>x; v.pb(x); } sort(v.begin(),v.end(),[&](const int &x,const int &y){ return loc[x]<loc[y]; }); v.pb(v[0]); for(int j=0;j<s;j++){ val[v[j]]++; val[lca(v[j],v[j+1])]--; } } dfs2(1,0); sort(ans.begin(),ans.end()); cout<<ans.size()<<endl; for(int x:ans) cout<<x<<" "; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);} int t=1; if(!t)cin>>t; while(t--){code();cout<<endl;} return 0; }

Compilation message (stderr)

railway.cpp: In function 'int main()':
railway.cpp:94:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |  bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~
railway.cpp:94:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |  bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".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...