답안 #19934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19934 2016-02-25T07:24:25 Z Namnamseo 트리 (kriii4_X) C++14
100 / 100
149 ms 10496 KB
#include <cstdio>
#include <map>
using namespace std;
map<int,int> vv;
int par [200010], vind;
int size[200010];
bool chk[200010];
int n,m;
inline int conv(int x){
    int& ret=vv[x];
    if(ret==0){
        ++vind;
        par [vind]=vind;
        size[vind]=1;
        ret =vind;
    }
    return ret;
}
int root(int x){ return (x==par[x])?x:(par[x]=root(par[x])); }
const int M=int(1e9)+7;
long long pow(long long x,long long y){
    if(y==0)return 1;
    if(y==1)return x;
    long long o=pow(x,y/2);
    if(y%2==0)return o*o%M;
    else return o*o%M*x%M;
}
int main()
{
    scanf("%d%d",&n,&m);
    int i,a,b;
    for(i=0;i<m;++i){
        scanf("%d%d",&a,&b);
        a=root(conv(a)); b=root(conv(b));
        if(a==b){
            puts("0"); return 0;
        }
        par [a]=b;
        size[b]+=size[a];
    }
    int allmul=1;
    for(i=1; i<=vind; ++i){
        a=root(i);
        if(chk[a]) continue;
        chk[a]=true;
        allmul=(allmul*1LL*size[a])%M;
    }
    if(n==m+1){
        printf("%d\n",1);
    } else
        printf("%d\n",int( pow(n, n-m-2) * allmul % M ));
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2972 KB Output is correct
2 Correct 0 ms 2972 KB Output is correct
3 Correct 0 ms 2972 KB Output is correct
4 Correct 0 ms 2972 KB Output is correct
5 Correct 0 ms 2972 KB Output is correct
6 Correct 0 ms 2972 KB Output is correct
7 Correct 0 ms 2972 KB Output is correct
8 Correct 0 ms 2972 KB Output is correct
9 Correct 0 ms 2972 KB Output is correct
10 Correct 0 ms 2972 KB Output is correct
11 Correct 0 ms 2972 KB Output is correct
12 Correct 0 ms 2972 KB Output is correct
13 Correct 0 ms 2972 KB Output is correct
14 Correct 0 ms 2972 KB Output is correct
15 Correct 0 ms 2972 KB Output is correct
16 Correct 0 ms 2972 KB Output is correct
17 Correct 0 ms 2972 KB Output is correct
18 Correct 0 ms 2972 KB Output is correct
19 Correct 0 ms 2972 KB Output is correct
20 Correct 0 ms 2972 KB Output is correct
21 Correct 0 ms 2972 KB Output is correct
22 Correct 0 ms 2972 KB Output is correct
23 Correct 0 ms 2972 KB Output is correct
24 Correct 0 ms 2972 KB Output is correct
25 Correct 0 ms 2972 KB Output is correct
26 Correct 0 ms 2972 KB Output is correct
27 Correct 0 ms 2972 KB Output is correct
28 Correct 0 ms 2972 KB Output is correct
29 Correct 0 ms 2972 KB Output is correct
30 Correct 0 ms 2972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3500 KB Output is correct
2 Correct 27 ms 4160 KB Output is correct
3 Correct 25 ms 4292 KB Output is correct
4 Correct 10 ms 3500 KB Output is correct
5 Correct 20 ms 3896 KB Output is correct
6 Correct 128 ms 10100 KB Output is correct
7 Correct 149 ms 10364 KB Output is correct
8 Correct 28 ms 4688 KB Output is correct
9 Correct 139 ms 10496 KB Output is correct
10 Correct 133 ms 9572 KB Output is correct
11 Correct 125 ms 7328 KB Output is correct
12 Correct 120 ms 7328 KB Output is correct
13 Correct 116 ms 7328 KB Output is correct
14 Correct 109 ms 7328 KB Output is correct
15 Correct 107 ms 7460 KB Output is correct
16 Correct 128 ms 7460 KB Output is correct
17 Correct 124 ms 7460 KB Output is correct
18 Correct 0 ms 2972 KB Output is correct
19 Correct 113 ms 7592 KB Output is correct
20 Correct 125 ms 7592 KB Output is correct
21 Correct 113 ms 7328 KB Output is correct
22 Correct 123 ms 7460 KB Output is correct
23 Correct 119 ms 7592 KB Output is correct
24 Correct 118 ms 7592 KB Output is correct
25 Correct 96 ms 7592 KB Output is correct
26 Correct 94 ms 7592 KB Output is correct
27 Correct 132 ms 9440 KB Output is correct
28 Correct 120 ms 9440 KB Output is correct
29 Correct 137 ms 7592 KB Output is correct
30 Correct 135 ms 7592 KB Output is correct