Submission #1110301

#TimeUsernameProblemLanguageResultExecution timeMemory
1110301guagua0407Railway (BOI17_railway)C++17
100 / 100
93 ms26976 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int dx[4]={0,0,1,-1}; int dy[4]={1,-1,0,0}; void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=1e5+5; vector<pair<int,int>> adj[mxn]; int st[mxn],en[mxn]; int cnt[mxn]; int depth[mxn]; int up[mxn][20]; int bit[mxn]; int res[mxn]; int timer=0; void update(int pos,int val){ for(;pos<mxn;pos+=(pos&-pos)){ bit[pos]+=val; } } int query(int pos){ int ans=0; for(;pos>0;pos-=(pos&-pos)){ ans+=bit[pos]; } return ans; } bool comp(int a,int b){ return st[a]<st[b]; } void dfs(int v,int p=0){ st[v]=++timer; up[v][0]=p; depth[v]=depth[p]+1; for(auto u:adj[v]){ if(u.f==p) continue; dfs(u.f,v); } en[v]=timer; } int lca(int a,int b){ if(depth[a]<depth[b]) swap(a,b); int len=depth[a]-depth[b]; for(int i=0;i<20;i++){ if(len&(1<<i)) a=up[a][i]; } if(a==b) return a; for(int i=19;i>=0;i--){ int ta=up[a][i]; int tb=up[b][i]; if(ta!=tb){ a=ta; b=tb; } } return up[a][0]; } void dfs2(int v,int p=0){ int prv=0; for(auto u:adj[v]){ if(u.f==p) continue; dfs2(u.f,v); int val=query(en[v])-query(st[v]-1); res[u.s]=val-prv; prv=val; } update(st[v],cnt[v]); } int main() {_ int n,m,k; cin>>n>>m>>k; for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; adj[a].push_back({b,i}); adj[b].push_back({a,i}); } dfs(1); for(int j=1;j<20;j++){ for(int i=1;i<=n;i++){ up[i][j]=up[up[i][j-1]][j-1]; } } for(int i=0;i<m;i++){ int t; cin>>t; vector<int> vec(t); for(int j=0;j<t;j++){ cin>>vec[j]; } sort(all(vec),comp); for(int j=0;j<t;j++){ int nxt=(j+1)%t; cnt[vec[j]]++; cnt[lca(vec[j],vec[nxt])]--; } } dfs2(1); vector<int> output; for(int i=0;i<n-1;i++){ if(res[i]>=k){ output.push_back(i+1); } } cout<<(int)output.size()<<'\n'; for(auto v:output){ cout<<v<<' '; } return 0; } //maybe its multiset not set //yeeorz //diaoborz

Compilation message (stderr)

railway.cpp: In function 'void setIO(std::string)':
railway.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen((s + ".out").c_str(), "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...