답안 #629999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629999 2022-08-15T13:45:58 Z Vladth11 Star Trek (CEOI20_startrek) C++14
45 / 100
76 ms 22992 KB
#include <bits/stdc++.h>
#define C 1
#define P 0
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "

using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;

const ll NMAX = 100001;
const ll VMAX = 101;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll base = 117;
const ll nr_of_bits = 18;
const ll inv2 = 500000004;

vector <ll> v[NMAX];
ll col[NMAX];
ll children[NMAX][2];
ll maximal[NMAX];
ll rosii[NMAX];
ll criticals[NMAX];
ll adv[NMAX];

void DFS(ll node, ll p){
    col[node] = P;
    for(auto x : v[node]){
        if(x == p) continue;
        DFS(x, node);
        children[node][col[x]]++;
    }
    if(children[node][C] == (ll)v[node].size() - (p != 0)){
        col[node] = P;
    }else{
        col[node] = C;
    }
    if(col[node] == P)
        rosii[node] = 1;
    for(auto x : v[node]){
        if(x == p) continue;
        if(col[node] != col[x] && children[node][C] >= (ll)v[node].size() - (p != 0) - 1){
            rosii[node] += rosii[x];
        }
    }
}

ll perdanti = 0;

void Rerooting(ll node, ll p){
    adv[node] = col[node];
    criticals[node] = rosii[node];
    if(adv[node] == P)
        perdanti++;
    for(auto x : v[node]){
        if(x == p) continue;
        ll cx = col[x], cnode = col[node], rx = rosii[x], rnode = rosii[node];
        children[node][col[x]]--;
        if(children[node][C] == v[node].size() - 1){
            col[node] = P;
        }else{
            col[node] = C;
        }
        children[x][col[node]]++;
        if(children[x][C] == v[x].size()){
            col[x] = P;
        }else{
            col[x] = C;
        }
        Rerooting(x, node);
        children[x][col[node]]--;
        col[x] = cx;
        col[node] = cnode;
        rosii[node] = rnode;
        rosii[x] = rx;
        children[node][col[x]]++;
    }
}

ll lgput(ll n, ll p){
    ll r = 1;
    while(p){
        if(p % 2){
            r *= n;
            r %= MOD;
        }
        n *= n;
        n %= MOD;
        p /= 2;
    }
    return r;
}

int main() {
    //ifstream cin(".in");
    //ofstream cout(".out");
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, d, i;
    cin >> n >> d;
    if(n == 2){
        cout << lgput(4, d);
        return 0;
    }
    for(i = 1; i < n; i++){
        ll a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    DFS(1, 0);
    Rerooting(1, 0);
    ll schimba = 1LL * perdanti * criticals[1];
    schimba %= MOD;
    if(adv[1] == P){
        cout << schimba;
    }else{
        cout << (1LL * n * n - schimba + MOD) % MOD;
    }
    return 0;
}

Compilation message

startrek.cpp: In function 'void Rerooting(ll, ll)':
startrek.cpp:62:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         if(children[node][C] == v[node].size() - 1){
      |            ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
startrek.cpp:68:27: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         if(children[x][C] == v[x].size()){
      |            ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 2 ms 2772 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 3 ms 2772 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2768 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 3 ms 2772 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2768 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 71 ms 16324 KB Output is correct
13 Correct 76 ms 22992 KB Output is correct
14 Correct 54 ms 10824 KB Output is correct
15 Correct 68 ms 10864 KB Output is correct
16 Correct 59 ms 10836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 3 ms 2772 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2768 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Incorrect 2 ms 2772 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 3 ms 2772 KB Output is correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2768 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 71 ms 16324 KB Output is correct
13 Correct 76 ms 22992 KB Output is correct
14 Correct 54 ms 10824 KB Output is correct
15 Correct 68 ms 10864 KB Output is correct
16 Correct 59 ms 10836 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Incorrect 2 ms 2772 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Incorrect 2 ms 2772 KB Output isn't correct
3 Halted 0 ms 0 KB -