Submission #1156282

#TimeUsernameProblemLanguageResultExecution timeMemory
1156282mmdrzadaStar Trek (CEOI20_startrek)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h>

#define int long long
using namespace std;


#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pii pair<int, int>
#define S second
#define F first
#define sep ' '
#define vi vector<int>
#define mid (l+r)/2
#define pbb pair<bool, bool>
#define trint array<int, 3>
const int N = 1e3+10, M = 1e9+7;
int n, d;
vi adj[N];
int exi, stat;
int cnt[2][2];

bool dfs(int v, int p = -1) {
    if (v == exi && stat == false) return true;
    for(int neigh: adj[v]) {
        if (neigh == p) continue;
        if (dfs(neigh, v) == false) return true;
    }
    return false;
}

void solve() {
    cin >> n >> d;
    assert(n <= 1e3 && d <= 1e5);
    for(int i = 0 ; i < n-1 ; i ++) {
        int u, v; cin >> u >> v;u --, v --; adj[u].pb(v), adj[v].pb(u);
    }
    for(int root = 0 ; root < n ; root ++) {
        for(exi = 0; exi < n ; exi ++) {
            for(stat = 0; stat <= 1; stat++) {
                bool res = dfs(root);
                cnt[res][stat]++;
            }
        }
    }
    // cout << "#\n";
    if (n <= 200) {
    exi = -1;
    vi base(2);
    for(int root = 0 ; root < n ; root ++) {
        base[dfs(root)]++;
    }
    for(int i = 1 ; i <= d-1 ; i ++) {
        base = {
            (1ll * base[0] * cnt[0][0] % M + 1ll * base[1] * cnt[0][1] % M) % M,
            (1ll * base[0] * cnt[1][0] % M + 1ll * base[1] * cnt[1][1] % M) % M,
        };
    }
    int ans = 0;
    for(exi = 0; exi < n ; exi ++) {
        for(stat = 0; stat <= 1; stat++) {
            if (dfs(0)) {
                ans += base[stat];
                ans %= M;
            }
        }
    }
    cout << cnt[0][0]  << endl;
    } else {
        for(int i = 0  ;i < 2 ; i ++) {
            for(int j = 0 ; j < 2 ; j ++) {
                cout << cnt[i][j] << sep;
            }
            cout << endl;
        }
    }
}

int32_t main() {
    fastIO;

    solve();

    return 0; 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...