# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
19755 |
2016-02-25T05:17:26 Z |
xdoju |
트리 (kriii4_X) |
C++14 |
|
429 ms |
11640 KB |
#include <stdio.h>
#include <map>
#include <utility>
using namespace std;
const int MOD = 1000000007;
map<int, int> par;
map<int, int> cnt;
int getroot(int x){
if(par.find(x) == par.end()) par[x] = x;
if(par[x] == x) return x;
return (par[x] = getroot(par[x]));
}
int mul(int x, int y){ return (long long)x * y % MOD; }
int power(int x, int y){
if(y == 0) return 1;
int r = power(x, y / 2);
r = mul(r, r);
if(y % 2 == 1) r = mul(r, x);
return r;
}
int main(){
int N, M; scanf("%d%d", &N, &M);
bool val = true;
for(int i = 1; i <= M; i++){
int x, y; scanf("%d%d", &x, &y);
int px = getroot(x), py = getroot(y);
if(px == py) val = false;
else par[px] = py;
}
if(!val){ puts("0"); }
else{
for(pair<int, int> pp : par){
int x = pp.first;
cnt[getroot(x)]++;
}
int NN = N - (int)par.size() + (int)cnt.size();
int ans = 1;
if(NN != 1){
for(pair<int, int> pp : cnt) ans = mul(ans, pp.second);
ans = mul(ans, power(N, NN - 2));
}
printf("%d\n", ans);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1212 KB |
Output is correct |
2 |
Correct |
0 ms |
1212 KB |
Output is correct |
3 |
Correct |
0 ms |
1212 KB |
Output is correct |
4 |
Correct |
0 ms |
1212 KB |
Output is correct |
5 |
Correct |
0 ms |
1212 KB |
Output is correct |
6 |
Correct |
0 ms |
1212 KB |
Output is correct |
7 |
Correct |
0 ms |
1212 KB |
Output is correct |
8 |
Correct |
0 ms |
1212 KB |
Output is correct |
9 |
Correct |
0 ms |
1212 KB |
Output is correct |
10 |
Correct |
0 ms |
1212 KB |
Output is correct |
11 |
Correct |
0 ms |
1212 KB |
Output is correct |
12 |
Correct |
0 ms |
1212 KB |
Output is correct |
13 |
Correct |
0 ms |
1212 KB |
Output is correct |
14 |
Correct |
0 ms |
1212 KB |
Output is correct |
15 |
Correct |
0 ms |
1212 KB |
Output is correct |
16 |
Correct |
0 ms |
1212 KB |
Output is correct |
17 |
Correct |
0 ms |
1212 KB |
Output is correct |
18 |
Correct |
0 ms |
1212 KB |
Output is correct |
19 |
Correct |
0 ms |
1212 KB |
Output is correct |
20 |
Correct |
0 ms |
1212 KB |
Output is correct |
21 |
Correct |
0 ms |
1212 KB |
Output is correct |
22 |
Correct |
0 ms |
1212 KB |
Output is correct |
23 |
Correct |
0 ms |
1212 KB |
Output is correct |
24 |
Correct |
0 ms |
1212 KB |
Output is correct |
25 |
Correct |
0 ms |
1212 KB |
Output is correct |
26 |
Correct |
0 ms |
1212 KB |
Output is correct |
27 |
Correct |
0 ms |
1212 KB |
Output is correct |
28 |
Correct |
0 ms |
1212 KB |
Output is correct |
29 |
Correct |
0 ms |
1212 KB |
Output is correct |
30 |
Correct |
0 ms |
1212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
1740 KB |
Output is correct |
2 |
Correct |
83 ms |
2400 KB |
Output is correct |
3 |
Correct |
90 ms |
2532 KB |
Output is correct |
4 |
Correct |
30 ms |
1872 KB |
Output is correct |
5 |
Correct |
56 ms |
2268 KB |
Output is correct |
6 |
Correct |
404 ms |
10980 KB |
Output is correct |
7 |
Correct |
394 ms |
11244 KB |
Output is correct |
8 |
Correct |
391 ms |
4248 KB |
Output is correct |
9 |
Correct |
394 ms |
11640 KB |
Output is correct |
10 |
Correct |
395 ms |
9792 KB |
Output is correct |
11 |
Correct |
379 ms |
5568 KB |
Output is correct |
12 |
Correct |
375 ms |
5568 KB |
Output is correct |
13 |
Correct |
364 ms |
5568 KB |
Output is correct |
14 |
Correct |
361 ms |
5568 KB |
Output is correct |
15 |
Correct |
373 ms |
5700 KB |
Output is correct |
16 |
Correct |
243 ms |
5700 KB |
Output is correct |
17 |
Correct |
244 ms |
5700 KB |
Output is correct |
18 |
Correct |
0 ms |
1212 KB |
Output is correct |
19 |
Correct |
429 ms |
5832 KB |
Output is correct |
20 |
Correct |
402 ms |
5832 KB |
Output is correct |
21 |
Correct |
368 ms |
5568 KB |
Output is correct |
22 |
Correct |
390 ms |
5700 KB |
Output is correct |
23 |
Correct |
410 ms |
5964 KB |
Output is correct |
24 |
Correct |
397 ms |
5964 KB |
Output is correct |
25 |
Correct |
263 ms |
7152 KB |
Output is correct |
26 |
Correct |
259 ms |
7152 KB |
Output is correct |
27 |
Correct |
379 ms |
9660 KB |
Output is correct |
28 |
Correct |
379 ms |
9660 KB |
Output is correct |
29 |
Correct |
424 ms |
5832 KB |
Output is correct |
30 |
Correct |
426 ms |
5964 KB |
Output is correct |