# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
19995 |
2016-02-25T08:14:50 Z |
gs12117 |
트리 (kriii4_X) |
C++ |
|
195 ms |
11084 KB |
#include<stdio.h>
#include<map>
long long int n,m;
int mod=1000000007;
long long int ans;
std::map<int,int> mp;
int eg[100100][2];
int cnt;
int uft[200100];
int uftn[200100];
int mpow(int x,int y){
if(y==0)return 1;
long long int r=mpow(x,y/2);
r*=r;
r%=mod;
if(y%2==1){
r*=x;
r%=mod;
}
return r;
}
int uftf(int x){
if(x==uft[x])return x;
return uft[x]=uftf(uft[x]);
}
int main(){
int i,j;
scanf("%d%d",&n,&m);
for(i=0;i<m;i++){
scanf("%d%d",&eg[i][0],&eg[i][1]);
if(mp[eg[i][0]]==0){
cnt++;
mp[eg[i][0]]=cnt;
}
eg[i][0]=mp[eg[i][0]];
if(mp[eg[i][1]]==0){
cnt++;
mp[eg[i][1]]=cnt;
}
eg[i][1]=mp[eg[i][1]];
}
for(i=1;i<=cnt;i++){
uft[i]=i;
uftn[i]=1;
}
for(i=0;i<m;i++){
if(uftf(eg[i][0])!=uftf(eg[i][1])){
uftn[uftf(eg[i][0])]+=uftn[uftf(eg[i][1])];
uft[uftf(eg[i][1])]=uftf(eg[i][0]);
}
else{
printf("0");
return 0;
}
}
ans=1;
for(i=1;i<=cnt;i++){
if(uftf(i)==i){
ans*=uftn[i];
ans%=mod;
}
}
if(m==n-1)ans=1;
else ans*=mpow(n,n-m-2);
ans%=mod;
printf("%lld",ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3560 KB |
Output is correct |
2 |
Correct |
0 ms |
3560 KB |
Output is correct |
3 |
Correct |
0 ms |
3560 KB |
Output is correct |
4 |
Correct |
0 ms |
3560 KB |
Output is correct |
5 |
Correct |
0 ms |
3560 KB |
Output is correct |
6 |
Correct |
0 ms |
3560 KB |
Output is correct |
7 |
Correct |
0 ms |
3560 KB |
Output is correct |
8 |
Correct |
0 ms |
3560 KB |
Output is correct |
9 |
Correct |
0 ms |
3560 KB |
Output is correct |
10 |
Correct |
0 ms |
3560 KB |
Output is correct |
11 |
Correct |
0 ms |
3560 KB |
Output is correct |
12 |
Correct |
0 ms |
3560 KB |
Output is correct |
13 |
Correct |
0 ms |
3560 KB |
Output is correct |
14 |
Correct |
0 ms |
3560 KB |
Output is correct |
15 |
Correct |
0 ms |
3560 KB |
Output is correct |
16 |
Correct |
0 ms |
3560 KB |
Output is correct |
17 |
Correct |
0 ms |
3560 KB |
Output is correct |
18 |
Correct |
0 ms |
3560 KB |
Output is correct |
19 |
Correct |
0 ms |
3560 KB |
Output is correct |
20 |
Correct |
0 ms |
3560 KB |
Output is correct |
21 |
Correct |
0 ms |
3560 KB |
Output is correct |
22 |
Correct |
0 ms |
3560 KB |
Output is correct |
23 |
Correct |
0 ms |
3560 KB |
Output is correct |
24 |
Correct |
0 ms |
3560 KB |
Output is correct |
25 |
Correct |
0 ms |
3560 KB |
Output is correct |
26 |
Correct |
0 ms |
3560 KB |
Output is correct |
27 |
Correct |
0 ms |
3560 KB |
Output is correct |
28 |
Correct |
0 ms |
3560 KB |
Output is correct |
29 |
Correct |
0 ms |
3560 KB |
Output is correct |
30 |
Correct |
0 ms |
3560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
4088 KB |
Output is correct |
2 |
Correct |
31 ms |
4748 KB |
Output is correct |
3 |
Correct |
38 ms |
4880 KB |
Output is correct |
4 |
Correct |
11 ms |
4088 KB |
Output is correct |
5 |
Correct |
26 ms |
4484 KB |
Output is correct |
6 |
Correct |
181 ms |
10688 KB |
Output is correct |
7 |
Correct |
183 ms |
10952 KB |
Output is correct |
8 |
Correct |
137 ms |
6596 KB |
Output is correct |
9 |
Correct |
188 ms |
11084 KB |
Output is correct |
10 |
Correct |
174 ms |
10160 KB |
Output is correct |
11 |
Correct |
165 ms |
7916 KB |
Output is correct |
12 |
Correct |
142 ms |
7916 KB |
Output is correct |
13 |
Correct |
164 ms |
7916 KB |
Output is correct |
14 |
Correct |
140 ms |
7916 KB |
Output is correct |
15 |
Correct |
151 ms |
8048 KB |
Output is correct |
16 |
Correct |
173 ms |
8048 KB |
Output is correct |
17 |
Correct |
159 ms |
8048 KB |
Output is correct |
18 |
Correct |
0 ms |
3560 KB |
Output is correct |
19 |
Correct |
159 ms |
8180 KB |
Output is correct |
20 |
Correct |
152 ms |
8180 KB |
Output is correct |
21 |
Correct |
146 ms |
7916 KB |
Output is correct |
22 |
Correct |
164 ms |
8048 KB |
Output is correct |
23 |
Correct |
147 ms |
8180 KB |
Output is correct |
24 |
Correct |
148 ms |
8180 KB |
Output is correct |
25 |
Correct |
115 ms |
8180 KB |
Output is correct |
26 |
Correct |
121 ms |
8180 KB |
Output is correct |
27 |
Correct |
185 ms |
10028 KB |
Output is correct |
28 |
Correct |
195 ms |
10028 KB |
Output is correct |
29 |
Correct |
156 ms |
8180 KB |
Output is correct |
30 |
Correct |
150 ms |
8180 KB |
Output is correct |