Submission #6289925


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;

int N;
long long K;
long long MOD = 1000000007;
vector<int> graph[100005];
int sz[100005];
long long ans = 1;

void dfs(int n, int p){
    sz[n]++;
    if(!p){
        ans = K;
    }
    else{
        ans *= K-sz[p];
        sz[p]++;
        ans %= MOD;
    }
    for(int e : graph[n]){
        if(e == p){
            continue;
        }
        sz[e]++;
        dfs(e, n);
    }
}

int main(){
    cin >> N >> K;
    for(int i = 1; i<N; i++){
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(1, 0);
    cout << ans << endl;
}

Submission Info

Submission Time
Task E - Virus Tree 2
User AQT
Language C++14 (GCC 5.4.1)
Score 500
Code Size 685 Byte
Status
Exec Time 94 ms
Memory 9600 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 500 / 500 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 2 ms 2560 KB
02.txt 2 ms 2560 KB
03.txt 2 ms 2560 KB
04.txt 2 ms 2560 KB
05.txt 2 ms 2560 KB
06.txt 2 ms 2560 KB
07.txt 2 ms 2560 KB
08.txt 2 ms 2560 KB
09.txt 2 ms 2560 KB
10.txt 17 ms 3328 KB
11.txt 29 ms 3712 KB
12.txt 73 ms 5504 KB
13.txt 92 ms 5888 KB
14.txt 84 ms 5888 KB
15.txt 82 ms 5888 KB
16.txt 88 ms 6268 KB
17.txt 88 ms 6268 KB
18.txt 87 ms 6268 KB
19.txt 83 ms 6520 KB
20.txt 82 ms 6520 KB
21.txt 83 ms 6520 KB
22.txt 87 ms 6268 KB
23.txt 89 ms 6268 KB
24.txt 87 ms 6268 KB
25.txt 83 ms 6520 KB
26.txt 82 ms 6520 KB
27.txt 83 ms 6520 KB
28.txt 87 ms 6268 KB
29.txt 87 ms 6268 KB
30.txt 88 ms 6268 KB
31.txt 82 ms 6520 KB
32.txt 83 ms 6520 KB
33.txt 82 ms 6520 KB
34.txt 94 ms 9600 KB
35.txt 94 ms 9600 KB
s1.txt 2 ms 2560 KB
s2.txt 2 ms 2560 KB
s3.txt 2 ms 2560 KB