Submission #427831

# Submission time Handle Problem Language Result Execution time Memory
427831 2021-06-15T00:38:24 Z Ozy Star Trek (CEOI20_startrek) C++17
0 / 100
19 ms 2724 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;
    lli cant = 0;
    for (auto h : hijos[pos]) {
        if (h == padre) continue;
        cant++;
        res *= DFS(h,pos);
    }

    if (cant == 0) {
        if (si) original[pos] = 0;
        return 0;
    }

    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;

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

        if (prof%2 == 0){
            if (original[pos] == 0) {
                if (hijos[pos].size() <= 2) resuelve(h,pos,prof+1);
            }
            else if (original[h] == 0) resuelve(h,pos,prof+1);
        }
        else {
            if (original[pos] == 1) {
                if (hijos[pos].size() <= 2) resuelve(h,pos,prof+1);
            }
            else 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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Incorrect 19 ms 2724 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2636 KB Output is correct
2 Incorrect 2 ms 2636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Incorrect 19 ms 2724 KB Output isn't correct