Submission #336774

# Submission time Handle Problem Language Result Execution time Memory
336774 2020-12-16T18:54:39 Z dolphingarlic Star Trek (CEOI20_startrek) C++14
38 / 100
95 ms 16364 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll MOD = 1e9 + 7;

vector<int> graph[100001];
ll win_as_root[100001], critical[100001];

void dfs1(int node = 1, int parent = 0) {
    for (int i : graph[node]) if (i != parent) {
        dfs1(i, node);
        win_as_root[node] += (win_as_root[i] == 0);
    }
    if (!win_as_root[node]) critical[node] = 1;
    for (int i : graph[node]) if (i != parent) {
        if ((win_as_root[node] == 1 && !win_as_root[i]) || !win_as_root[node])
            critical[node] += critical[i];
    }
}

void dfs2(int node = 1, int parent = 0, int anc = 1) {
    win_as_root[node] += (anc == 0);
    for (int i : graph[node]) if (i != parent) {
        dfs2(i, node, win_as_root[node] - (win_as_root[i] == 0));
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, d;
    cin >> n >> d;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    dfs1();
    dfs2();

    ll lose_cnt = 0;
    for (int i = 1; i <= n; i++) lose_cnt += (win_as_root[i] == 0);
    if (win_as_root[1])
        cout << (n * n - lose_cnt * critical[1]) % MOD;
    else
        cout << lose_cnt * critical[1] % MOD;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Incorrect 2 ms 2796 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2796 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 2 ms 2796 KB Output is correct
10 Correct 2 ms 2796 KB Output is correct
11 Correct 2 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2796 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 2 ms 2796 KB Output is correct
10 Correct 2 ms 2796 KB Output is correct
11 Correct 2 ms 2796 KB Output is correct
12 Correct 73 ms 10988 KB Output is correct
13 Correct 95 ms 16364 KB Output is correct
14 Correct 70 ms 8576 KB Output is correct
15 Correct 70 ms 8556 KB Output is correct
16 Correct 73 ms 8556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2796 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 2 ms 2796 KB Output is correct
10 Correct 2 ms 2796 KB Output is correct
11 Correct 2 ms 2796 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Incorrect 2 ms 2796 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2796 KB Output is correct
8 Correct 2 ms 2796 KB Output is correct
9 Correct 2 ms 2796 KB Output is correct
10 Correct 2 ms 2796 KB Output is correct
11 Correct 2 ms 2796 KB Output is correct
12 Correct 73 ms 10988 KB Output is correct
13 Correct 95 ms 16364 KB Output is correct
14 Correct 70 ms 8576 KB Output is correct
15 Correct 70 ms 8556 KB Output is correct
16 Correct 73 ms 8556 KB Output is correct
17 Correct 2 ms 2668 KB Output is correct
18 Incorrect 2 ms 2796 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Incorrect 2 ms 2796 KB Output isn't correct