답안 #428379

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
428379 2021-06-15T11:10:33 Z Ozy Star Trek (CEOI20_startrek) C++17
0 / 100
15 ms 2676 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define debugsl(a) cout << #a << " = " << a << ", "
#define debug(a) cout << #a << " = " << a << endl;

#define MAX 100000
#define mod 1000000007

bool si;
lli n,d,a,b,total,g,p;
vector<lli> hijos[MAX+2];
lli estado[MAX+2],original[MAX+2];

lli DFS (lli pos, lli padre) {

    lli res = 1;
    for (auto h : hijos[pos]) {
        if (h == padre) continue;
        res *= DFS(h,pos);
    }

    if (res == 0) {
        if (si) original[pos] = 1;
        return 1;
    }
    else {
        if (si) original[pos] = 0;
        return 0;
    }
}

void resuelve(lli pos, lli padre, lli prof) {

    if (prof%2 == 0) total += p;
    else if (original[pos] == 0) total += g;

    if (total > mod) total %= mod;

    lli ap = 0;
    lli ag = 0;
    for(auto h : hijos[pos]) {
        if (h == padre) continue;
        if (original[h] == 0) ap++;
        else ag++;
    }

    if (prof%2 && original[pos] == 1 && ap > 1) return;

    for(auto h : hijos[pos]) {
        if (h == padre) continue;

        if (prof%2 && original[pos] == 1 && original[h] == 0) resuelve(h,pos,prof+1);
        else if (prof%2 && original[pos] == 0) resuelve(h,pos,prof+1);
        else if (!(prof%2)) resuelve(h,pos,prof+1);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> d;
    rep(i,1,n-1) {
        cin >> a >> b;
        hijos[a].push_back(b);
        hijos[b].push_back(a);
    }

    si = true;
    rep(i,1,n) {
        estado[i] = DFS(i,0);

        si = false;
        if (estado[i] == 0) p++;
        else g++;
    }

    total = 0;
    resuelve(1,0,0);

    cout << total;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2588 KB Output is correct
2 Incorrect 15 ms 2676 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2588 KB Output is correct
2 Incorrect 15 ms 2676 KB Output isn't correct