답안 #566905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566905 2022-05-23T05:55:36 Z azberjibiou Star Trek (CEOI20_startrek) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fir first
#define sec second
#define pdd pair<long double, long double>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double
#define pmax pair<__int128, __int128>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
int dx[4]= {0, 1, 0, -1}, dy[4]= {1, 0, -1, 0};
int ddx[8]={1, 1, 0, -1, -1, -1, 0, 1}, ddy[8]={0, 1, 1, 1, 0, -1, -1, -1};
const int mxN=100025;
const int mxM=300005;
const int mxK=1000000000;
const ll MOD=1000'000'007;
const ll INF=1000000000000000005;
ll N, D;
vector <int> v[mxN];
ll outw[mxN];
ll downw[mxN], upw[mxN];
ll degL[mxN];
bool W[mxN];
ll numw;
void dfs_downw(int now, int pre)
{
    for(int nxt : v[now])   if(nxt!=pre)
    {
        dfs_downw(nxt, now);
    }
    downw[now]=(outw[now]==0 ? 1 : 0);
    if(now!=1)  outw[pre]+=downw[now];
}
void dfs_upw(int now, int pre)
{
    if(now!=1)
    {
        upw[now]=(outw[pre]-downw[now]==0 ? 1 : 0);
        outw[now]+=upw[now];
    }
    for(int nxt : v[now])   if(nxt!=pre)
    {
        dfs_upw(nxt, now);
    }
}
ll dfs1(int now, int pre, int dep)
{
    ll sum=0;
    bool ok=true;
    for(int nxt : v[now])   if(W[nxt] && nxt!=pre && degL[nxt]==0)
    {
        ok=false;
        sum+=dfs1(nxt, now, 1-dep);
    }
    if(sum==0 && !ok)   return 0;
    if(!ok) return sum+1;
    if(ok)
    {
        return dep;
    }
}
ll dfs2(int now, int pre, bool cond)
{
    ll sum=!W[now];
    for(int nxt : v[now])   if(nxt!=pre && W[nxt]+W[now]==1)
    {
        if(degL[nxt]>=3)    continue;
        sum+=dfs2(nxt, now, cond);
    }
    return sum;
}
int main()
{
    gibon
    cin >> N >> D;
    for(int i=1;i<N;i++)
    {
        int a, b;   cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs_downw(1, -1);
    dfs_upw(1, -1);
    for(int i=1;i<=N;i++)   if(outw[i]>=1)  W[i]=true;
    for(int i=1;i<=N;i++)   numw+=W[i];
    for(int i=1;i<=N;i++)   for(int ele : v[i]) degL[i]+=1-W[ele];
    ll ans=0;
    if(W[1])
    {
        ans=N*N;
        if(degL[1]==0)
        {
            ans-=dfs1(1, -1, 0)/2*(N-numw);
        }
        if(degL[1]==1)
        {
            ans-=dfs2(1, -1)*(N-numw);
        }
    }
    else
    {
        ans+=dfs2(1, -1)*(N-numw);
    }
    cout << ans;
}

/*
10 1
1 9
9 6
6 5
5 3
5 7
7 2
2 8
8 4
4 10
*/

Compilation message

startrek.cpp: In function 'int main()':
startrek.cpp:101:28: error: too few arguments to function 'll dfs2(int, int, bool)'
  101 |             ans-=dfs2(1, -1)*(N-numw);
      |                            ^
startrek.cpp:66:4: note: declared here
   66 | ll dfs2(int now, int pre, bool cond)
      |    ^~~~
startrek.cpp:106:24: error: too few arguments to function 'll dfs2(int, int, bool)'
  106 |         ans+=dfs2(1, -1)*(N-numw);
      |                        ^
startrek.cpp:66:4: note: declared here
   66 | ll dfs2(int now, int pre, bool cond)
      |    ^~~~
startrek.cpp: In function 'll dfs1(int, int, int)':
startrek.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type]
   65 | }
      | ^