제출 #553396

#제출 시각아이디문제언어결과실행 시간메모리
553396new_accRailway (BOI17_railway)C++14
100 / 100
147 ms26384 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pitem item* using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; const int N=1e5+10; const int SS=1<<19; const int INFi=2e9; const ll INFl=1e13; const ll mod2=998244353; const ll mod=1e9+7; const ll mod3=1000696969; const ll p=70032301; const ull p2=913; const int L=17; int n,m,k,oj[N],il[N],jump[N][L+1],pre[N],l,dep[N],dod[N]; pair<int,int> w[N]; vi graf[N]; void dfs(int v,int o){ jump[v][0]=o; for(int i=1;i<=L;i++) jump[v][i]=jump[jump[v][i-1]][i-1]; pre[v]=++l; dep[v]=dep[o]+1; for(auto u:graf[v]){ if(u==o) continue; dfs(u,v); } } void dfs2(int v,int o){ il[v]+=dod[v]; for(auto u:graf[v]){ if(u==o) continue; dfs2(u,v); il[v]+=il[u]; } } int lca(int a,int b){ if(dep[a]<dep[b]) swap(a,b); for(int i=L;i>=0;i--) if(dep[jump[a][i]]>=dep[b]) a=jump[a][i]; if(a==b) return a; int res=0; for(int i=L;i>=0;i--){ if(jump[a][i]==jump[b][i]) res=jump[a][i]; else a=jump[a][i],b=jump[b][i]; } return res; } void solve(){ cin>>n>>m>>k; k<<=1; for(int a,b,i=1;i<n;i++){ cin>>a>>b; graf[a].push_back(b),graf[b].push_back(a); w[i]={a,b}; } dfs(1,1); for(int i=1;i<n;i++){ if(dep[w[i].fi]<dep[w[i].se]) oj[w[i].se]=i; else oj[w[i].fi]=i; } for(int i=1;i<=m;i++){ int xd; cin>>xd; vector<pair<int,int> >v; while(xd--){ int curr; cin>>curr; v.push_back({pre[curr],curr}); } sort(v.begin(),v.end()); v.push_back(v[0]); for(int j=0;j<v.size()-1;j++) dod[v[j].se]++,dod[v[j+1].se]++,dod[lca(v[j].se,v[j+1].se)]-=2; } dfs2(1,1); vi res; for(int i=2;i<=n;i++) if(il[i]>=k) res.push_back(oj[i]); cout<<res.size()<<"\n"; sort(res.begin(),res.end()); for(auto u:res) cout<<u<<" "; cout<<"\n"; } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); solve(); }

컴파일 시 표준 에러 (stderr) 메시지

railway.cpp: In function 'void solve()':
railway.cpp:76:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for(int j=0;j<v.size()-1;j++) dod[v[j].se]++,dod[v[j+1].se]++,dod[lca(v[j].se,v[j+1].se)]-=2;
      |               ~^~~~~~~~~~~
#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...