제출 #1084119

#제출 시각아이디문제언어결과실행 시간메모리
1084119modwweRailway (BOI17_railway)C++17
100 / 100
69 ms26064 KiB
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
//#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while(c<'0'||c>'9')
    {
        c=getchar_unlocked();
    }
    while(c>='0'&&c<='9')
    {
        x=(x<<1)+(x<<3)+c-'0';
        c=getchar_unlocked();
    }
    return x;
}

void phongbeo();
const int inf=1e9;
const int mod2=998244353;
const int  mod1=998244353;
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a,b,c;
};
struct id
{
    int a,b,c,d;
};
struct ie
{
    int a,b,c,d,e;

};

int n,m,s1,s2,s4,s3,sf,k,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,s33,dem3,dem4,l,r,mid,l2,r2,center;
int  i,s10,s12;
int kk;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
//    fin(task),fou(task);
#endif
    NHP
    /// cin>>s1;
    //modwwe
    phongbeo(),down
//checktime
}
int dp[100001];
vector<ib> v[100001];
int depth[100001];
int st[17][100001];
vector<int> v2,v3;
int in[100001];
int lca(int u,int v)
{
    if(depth[u]>depth[v])swap(u,v);
    int ss=depth[v]-depth[u];
    for(int j=0; j<17; j++)
    {
        if(bit(ss,j))
        {
            v=st[j][v];
        }
    }
    if(v==u) return v;
    for(int j=16; j>=0; --j)
    {
        if(st[j][u]!=st[j][v])
        {
            u=st[j][u];
            v=st[j][v];
        }
    }
    return st[0][v];
}
void dfs(int x,int y)
{ st[0][x]=y;
in[x]=++dem;
depth[x]=depth[y]+1;
     for(auto f:v[x])
           if(f.a!=y)
             dfs(f.a,x);
}
void dfs2(int x,int y)
 {
      for(auto f:v[x])
       if(f.a!=y){
        dfs2(f.a,x),dp[x]+=dp[f.a];
         if(dp[f.a]>=k)v3.pb(f.b);
        }
 }
 bool cmp(int x,int y)
 {
      return  in[x]<in[y];
 }
void phongbeo()
{
    cin>>n>>m>>k;
   for(int i=1;i<n;i++)
   cin>>l>>r,v[l].pb({r,i}),v[r].pb({l,i});
    dfs(1,0);
    for(int i=1;i<17;i++)
        for(int j=1;j<=n;j++)
        st[i][j]=st[i-1][st[i-1][j]];
      while(m--)
        {
            cin>>l;
            v2.clear();
             for(int i=1;i<=l;i++)
             {
                 cin>>r;
                  v2.pb(r);
             }
             sort(v2.begin(),v2.end(),cmp);
              for(int i=0;i<l;i++)
              {
                  if(i==0)
                  {
                      s2=lca(v2[0],v2.back());
                      dp[v2[0]]++;
                      dp[s2]--;
                  }
                  else
                  {
                       s2=lca(v2[i],v2[i-1]);
                       dp[v2[i]]++;
                       dp[s2]--;
                  }
              }
        }
         dfs2(1,0);
    sort(v3.begin(),v3.end());
    cout<<v3.size(),down
    for(auto x:v3)
         cout<<x<<" ";
}

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

railway.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main()
      | ^~~~
#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...