Submission #1115958

#TimeUsernameProblemLanguageResultExecution timeMemory
1115958KhoaDuyRailway (BOI17_railway)C++14
36 / 100
99 ms58532 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define int long long const int MAXN=1e5; vector<vector<int>> graph(MAXN+1); int paidx[MAXN+1]; int w[MAXN+1]={0}; int depth[MAXN+1]; vector<vector<int>> sparse(18); int in[MAXN+1]; int out[MAXN+1]; vector<int> loga; int cmp(int a,int b){ if(depth[a]<depth[b]){ return a; } return b; } void DFS(int u,int p){ in[u]=sparse[0].size(); loga.push_back(loga[loga.size()>>1]+1); sparse[0].push_back(u); for(int v:graph[u]){ if(v!=p){ depth[v]=depth[u]+1; DFS(v,u); } } out[u]=sparse[0].size()-1; if(p!=-1){ loga.push_back(loga[loga.size()>>1]+1); sparse[0].push_back(p); } } int LCA(int u,int v){ int l=in[u],r=in[v]; if(l>r){ swap(l,r); } return cmp(sparse[loga[r-l+1]][l],sparse[loga[r-l+1]][r-(1<<loga[r-l+1])+1]); } bool cmp2(int a,int b){ return (in[a]<in[b]); } vector<int> ans; int k; void DFS2(int u,int p){ for(int v:graph[u]){ if(v!=p){ DFS2(v,u); w[u]+=w[v]; } } if(w[u]>=k){ ans.push_back(paidx[u]); } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin >> n >> m >> k; loga.push_back(-1); vector<pair<int,int>> edges; for(int i=0;i<n-1;i++){ int a,b; cin >> a >> b; edges.push_back({a,b}); graph[a].push_back(b); graph[b].push_back(a); } depth[1]=0; DFS(1,-1); for(int i=1;i<18;i++){ for(int j=0;j+(1<<i)<=sparse[0].size();j++){ sparse[i].push_back(cmp(sparse[i-1][j],sparse[i-1][j+(1<<(i-1))])); } } while(m--){ int s; cin >> s; vector<int> a(s); for(int i=0;i<s;i++){ cin >> a[i]; } sort(a.begin(),a.end(),cmp2); for(int i=0;i+1<s;i++){ w[a[i]]++; w[a[i+1]]++; w[LCA(a[i],a[i+1])]-=2; } } for(int i=0;i<edges.size();i++){ int u=edges[i].first,v=edges[i].second; if(depth[u]>depth[v]){ swap(u,v); } paidx[v]=i+1; } DFS2(1,-1); sort(ans.begin(),ans.end()); cout << ans.size() << endl; for(int i=0;i<ans.size();i++){ cout << ans[i] << ' '; } }

Compilation message (stderr)

railway.cpp: In function 'int main()':
railway.cpp:76:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |         for(int j=0;j+(1<<i)<=sparse[0].size();j++){
      |                     ~~~~~~~~^~~~~~~~~~~~~~~~~~
railway.cpp:94:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for(int i=0;i<edges.size();i++){
      |                 ~^~~~~~~~~~~~~
railway.cpp:104:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |     for(int i=0;i<ans.size();i++){
      |                 ~^~~~~~~~~~~
#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...