提出 #6368441
ソースコード 拡げる
#include <bits/stdc++.h>
#define inf 4294967295
#define N 500000
#define LL long long
#define pi acos(-1)
#define MO 1000000007
using namespace std;
LL ans;
int ot[N],ne[N],g[N],e,n,k;
LL fac[N];
void add(int x,int y){
ot[++e]=y,ne[e]=g[x],g[x]=e;
ot[++e]=x,ne[e]=g[y],g[y]=e;
}
void dfs(int x,int fa){
int son = 0;
for (int p = g[x]; p; p = ne[p]){
int y = ot[p];
if (y != fa){
son++;
dfs(y,x);
}
}
if (son){
if (fa == -1){
if (son <= k - 1) ans = ans * (k-1) % MO * fac[k-son] % MO;
else ans = 0;
} else {
if (son <= k - 2) ans = ans * fac[k-1-son] % MO;
else ans = 0;
}
}
}
int main(){
scanf("%d%d",&n,&k);
fac[k]=fac[k-1]=1;
fac[k-2]=k-2;
for (int i = k-3; i >= 1; --i) fac[i] = (fac[i+1] * i) % MO;
for (int i = 1; i < n; ++i) {
int x,y;
scanf("%d%d",&x,&y);
add(x,y);
}
ans = k;
dfs(1,-1);
cout << ans << endl;
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - Virus Tree 2 |
| ユーザ | ZzZZCHS |
| 言語 | C++14 (GCC 5.4.1) |
| 得点 | 500 |
| コード長 | 943 Byte |
| 結果 | AC |
| 実行時間 | 25 ms |
| メモリ | 10368 KiB |
コンパイルエラー
./Main.cpp: In function ‘int main()’:
./Main.cpp:40:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&k);
^
./Main.cpp:46:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&x,&y);
^
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | s1.txt, s2.txt, s3.txt |
| All | 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 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 01.txt | AC | 2 ms | 2304 KiB |
| 02.txt | AC | 2 ms | 2304 KiB |
| 03.txt | AC | 2 ms | 2304 KiB |
| 04.txt | AC | 2 ms | 6400 KiB |
| 05.txt | AC | 2 ms | 6400 KiB |
| 06.txt | AC | 2 ms | 6400 KiB |
| 07.txt | AC | 2 ms | 6400 KiB |
| 08.txt | AC | 2 ms | 6400 KiB |
| 09.txt | AC | 2 ms | 6400 KiB |
| 10.txt | AC | 6 ms | 6528 KiB |
| 11.txt | AC | 8 ms | 6400 KiB |
| 12.txt | AC | 18 ms | 6656 KiB |
| 13.txt | AC | 22 ms | 7552 KiB |
| 14.txt | AC | 20 ms | 6784 KiB |
| 15.txt | AC | 20 ms | 6784 KiB |
| 16.txt | AC | 22 ms | 7552 KiB |
| 17.txt | AC | 22 ms | 7552 KiB |
| 18.txt | AC | 21 ms | 7168 KiB |
| 19.txt | AC | 21 ms | 7552 KiB |
| 20.txt | AC | 21 ms | 7552 KiB |
| 21.txt | AC | 20 ms | 7168 KiB |
| 22.txt | AC | 22 ms | 7552 KiB |
| 23.txt | AC | 22 ms | 7552 KiB |
| 24.txt | AC | 21 ms | 7168 KiB |
| 25.txt | AC | 20 ms | 7552 KiB |
| 26.txt | AC | 20 ms | 7552 KiB |
| 27.txt | AC | 20 ms | 7168 KiB |
| 28.txt | AC | 22 ms | 7552 KiB |
| 29.txt | AC | 22 ms | 7552 KiB |
| 30.txt | AC | 21 ms | 7168 KiB |
| 31.txt | AC | 20 ms | 7552 KiB |
| 32.txt | AC | 21 ms | 7552 KiB |
| 33.txt | AC | 20 ms | 7168 KiB |
| 34.txt | AC | 25 ms | 10368 KiB |
| 35.txt | AC | 25 ms | 10240 KiB |
| s1.txt | AC | 2 ms | 6400 KiB |
| s2.txt | AC | 2 ms | 6400 KiB |
| s3.txt | AC | 2 ms | 6400 KiB |