이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define mkp make_pair
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
typedef long double ld;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<62);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int n,m,k,i,x,y,in[nmax],out[nmax],tin,up[nmax][20],mn,mx,ed[nmax],rs,id[nmax],vl[nmax],lc;
vector<pair<int,int> >a[nmax];
vector<int>vc;
bitset<nmax>on;
pair<int,int>c[nmax];
void dfs(int x,int p)
{
in[x]=++tin;
id[tin]=x;
up[x][0]=p;
for(int i=1;i<19;i++)up[x][i]=up[up[x][i-1]][i-1];
for(int i=0;i<(int)a[x].size();i++)
{
int y=a[x][i].fr;
if(y==p)continue;
dfs(y,x);
}
out[x]=++tin;
}
int anc(int x,int y)
{
return in[x]<=in[y] && out[y]<=out[x];
}
int lca(int x,int y)
{
if(anc(x,y))return x;
if(anc(y,x))return y;
for(int i=18;i>=0;i--)if(!anc(up[x][i],y))x=up[x][i];
return up[x][0];
}
void sol(int x,int p,int e)
{
for(int i=0;i<(int)a[x].size();i++)
{
int y=a[x][i].fr;
if(y==p)continue;
sol(y,x,a[x][i].sc);
vl[x]+=vl[y];
}
if(vl[x]>=2*k)vc.pb(e);
//cout<<vl[x]<<" "<<x<<" "<<p<<endl;
}
int main()
{
//freopen("sol.in","r",stdin);
//freopen("sol.out","w",stdout);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
cin>>n>>m>>k;
for(i=1;i<n;i++)
{
cin>>x>>y;
a[x].pb(mkp(y,i));
a[y].pb(mkp(x,i));
}
dfs(1,1);
while(m--)
{
cin>>x;
lc=-1;
for(i=0;i<x;i++)
{
cin>>c[i].sc;
c[i].fr=in[c[i].sc];
}
sort(c,c+x);
for(i=0;i<x;i++)
{
//cout<<c[i].sc<<" "<<c[i-1].sc<<endl;
vl[c[i].sc]++;
vl[c[(i+1)%x].sc]++;
//vl[c[(i+1)%x].sc]++;
vl[lca(c[i].sc,c[(i+1)%x].sc)]-=2;
}
}
sol(1,1,0);
sort(vc.begin(),vc.end());
cout<<(int)vc.size()<<endl;
for(i=0;i<(int)vc.size();i++)cout<<vc[i]<<" ";
cout<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
railway.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("O3")
railway.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization("unroll-loops")
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |