답안 #597101

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
597101 2022-07-15T13:47:59 Z kamelfanger83 Star Trek (CEOI20_startrek) C++14
38 / 100
109 ms 13860 KB
#include <iostream>
#include <vector>

using namespace std;

#define int long long

const int module = 1e9+7;

signed main(){
    int n, d; cin >> n >> d;
    vector<vector<int>> cons (n);
    int u, v;
    for (int reader = 0; reader < n - 1; ++reader) {
        cin >> u >> v;
        u--; v--;
        cons[u].push_back(v);
        cons[v].push_back(u);
    }
    vector<int> wins (n), redchild (n);

    auto dfswins = [&](auto&& self, int i, int from) -> int{
        int red = 0, redi;
        for(int c : cons[i]){
            if(c == from) continue;
            if(self(self, c, i) == 0){
                red++;
                redi = c;
            }
        }
        if(red == 1) redchild[i] = redi;
        return wins[i] = red;
    };

    dfswins(dfswins, 0, -1);

    int redforce = 0;

    auto findredforce = [&](auto&& self, int i, int from) -> void {
        if(wins[i] == 0){
            redforce++;
            for(int c : cons[i]){
                if(c == from) continue;
                self(self, c, i);
            }
        }
        if(wins[i] == 1){
            self(self, redchild[i], i);
        }
    };

    findredforce(findredforce, 0, -1);

    vector<int> winup (n, -1);

    int violet = 0;

    auto dfs3 = [&](auto&& self, int i, int from) -> void{
        if(from == -1){
            winup[i] = false;
            if(wins[i] == false) violet++;
        }
        else if(wins[i] == 0){
            if(winup[from] == false && wins[from] == 1) winup[i] = true;
            else{
                winup[i] = false;
                violet++;
            }
        }
        else{
            if(winup[from] == false && wins[from] == 0) winup[i] = true;
            else winup[i] = false;
        }
        for(int c : cons[i]){
            if(c == from) continue;
            self(self, c, i);
        }
    };

    dfs3(dfs3, 0, -1);

    if(wins[0] > 0) cout << (n*n - violet*redforce)%module;
    else cout << (violet*redforce)%module;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 95 ms 10704 KB Output is correct
13 Correct 101 ms 13860 KB Output is correct
14 Correct 75 ms 9044 KB Output is correct
15 Correct 92 ms 9112 KB Output is correct
16 Correct 109 ms 9164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Incorrect 1 ms 340 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 95 ms 10704 KB Output is correct
13 Correct 101 ms 13860 KB Output is correct
14 Correct 75 ms 9044 KB Output is correct
15 Correct 92 ms 9112 KB Output is correct
16 Correct 109 ms 9164 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -