답안 #597086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
597086 2022-07-15T13:26:27 Z kamelfanger83 Star Trek (CEOI20_startrek) C++14
0 / 100
1 ms 340 KB
#include <iostream>
#include <vector>

using namespace std;

#define int long long

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++;
        if(wins[i] < 2){
            for(int c : cons[i]){
                if(c == from) continue;
                self(self, c, 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;
    else cout << violet*redforce;

    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 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 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 -