# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
20019 |
2016-02-25T08:39:53 Z |
emppu |
트리 (kriii4_X) |
C++14 |
|
169 ms |
10812 KB |
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <list>
#include <bitset>
#include <tuple>
using namespace std;
#define f0(_X,_Y) for(int (_X)=0;(_X)<(_Y);++(_X))
#define f1(_X,_Y) for(int (_X)=1;(_X)<=(_Y);++(_X))
#define ff(_X,_Y,_Z) for(int (_X)=(_Y);(_X)<=(_Z);++(_X))
#define fF(_X,_Y,_Z) for(int (_X)=(_Y);(_X)<(_Z);++(_X))
#define rf0(_X,_Y) for(int _X=(_Y)-1;(_X)>=0;--(_X))
#define rf1(_X,_Y) for(int _X=(_Y);(_X)>0;--(_X))
#define rff(_X,_Y,_Z) for(int _X=(_Y);(_X)>=(_Z);--(_X))
#define rfF(_X,_Y,_Z) for(int _X=(_Y);(_X)>(_Z);--(_X))
#define PRT(_X) std::cout<< #_X ": "<<_X<<std::endl;
#define scan1(_X) scanf("%d",&_X);
#define scan2(_X,_Y) scanf("%d%d",&_X,&_Y);
#define scan3(_X,_Y,_Z) scanf("%d%d%d",&_X,&_Y,&_Z);
#define define1(_1) int _1; scan1(_1)
#define define2(_1,_2) int _1,_2; scan2(_1,_2)
#define define3(_1,_2,_3) int _1,_2,_3; scan3(_1,_2,_3)
#define EXPAND(_1) _1
#define SELECT(_1,_2,_3,_4,NAME,...) NAME
#define scan(...) EXPAND(SELECT(__VA_ARGS__, scan4, scan3, scan2, scan1)(__VA_ARGS__))
#define define(...) EXPAND(SELECT(__VA_ARGS__, define4, define3, define2, define1)(__VA_ARGS__))
#define print(_X) printf("%d\n",_X)
#define PAIR_STRUCT(_T,_X,_Y,...) struct _T{int _X,_Y,##__VA_ARGS__; bool friend operator < (const _T &p, const _T &q){if(p._X!=q._X) return p._X<q._X; return p._Y<q._Y;}}
typedef long long ll;
const int MOD = 1000000007;
ll mul(ll a, ll b){return a*b%MOD;}
ll add(ll a, ll b){return (a+b)%MOD;}
ll inv(ll a, ll b=MOD)
{
ll s = 0; ll old_s = 1;
ll r = b; ll old_r = a;
while (r!=0)
{
ll quotient = old_r / r;
tie(old_r, r) = make_tuple(r, old_r - quotient * r);
tie(old_s, s) = make_tuple(s, old_s - quotient * s);
}
ll inv = old_s%MOD;
if(inv<0) inv += MOD;
return inv;
}
const int N = 200002;
map<int,int> no;
int r[N],sz[N];
int root(int node)
{
if(r[node]) return r[node]=root(r[node]);
return node;
}
ll powmod(ll a, ll b)
{
a %= MOD;
b %= MOD-1;
ll p = 1;
ll sq = a;
for(int i=1;i<=b;i*=2)
{
if(b&i)
{
p = mul(p,sq);
}
sq = mul(sq,sq);
}
return p;
}
int main()
{
define(n,m);
int cnt=0;
bool cycle = false;
f1(i,m)
{
define(s,e);
if(no.find(s)==no.end()) no[s]=++cnt, s=cnt, sz[cnt]=1; else s=no[s];
if(no.find(e)==no.end()) no[e]=++cnt, e=cnt, sz[cnt]=1; else e=no[e];
int r1 = root(s);
int r2 = root(e);
if(r1!=r2)
{
r[r2]=r1;
sz[r1]+=sz[r2];
}
else
{
cycle=true;
break;
}
}
if(cycle)
{
print(0);
return 0;
}
if(m==n-1)
{
print(1);
return 0;
}
ll ans=1;
f1(i,cnt) if(r[i]==0) ans=mul(ans,sz[i]);
ans = mul(ans,powmod(n,n-m-2));
printf("%lld\n",ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
3288 KB |
Output is correct |
2 |
Correct |
0 ms |
3288 KB |
Output is correct |
3 |
Correct |
0 ms |
3288 KB |
Output is correct |
4 |
Correct |
0 ms |
3288 KB |
Output is correct |
5 |
Correct |
0 ms |
3288 KB |
Output is correct |
6 |
Correct |
0 ms |
3288 KB |
Output is correct |
7 |
Correct |
0 ms |
3288 KB |
Output is correct |
8 |
Correct |
0 ms |
3288 KB |
Output is correct |
9 |
Correct |
0 ms |
3288 KB |
Output is correct |
10 |
Correct |
0 ms |
3288 KB |
Output is correct |
11 |
Correct |
0 ms |
3288 KB |
Output is correct |
12 |
Correct |
0 ms |
3288 KB |
Output is correct |
13 |
Correct |
0 ms |
3288 KB |
Output is correct |
14 |
Correct |
0 ms |
3288 KB |
Output is correct |
15 |
Correct |
0 ms |
3288 KB |
Output is correct |
16 |
Correct |
0 ms |
3288 KB |
Output is correct |
17 |
Correct |
0 ms |
3288 KB |
Output is correct |
18 |
Correct |
0 ms |
3288 KB |
Output is correct |
19 |
Correct |
0 ms |
3288 KB |
Output is correct |
20 |
Correct |
0 ms |
3288 KB |
Output is correct |
21 |
Correct |
0 ms |
3288 KB |
Output is correct |
22 |
Correct |
0 ms |
3288 KB |
Output is correct |
23 |
Correct |
0 ms |
3288 KB |
Output is correct |
24 |
Correct |
0 ms |
3288 KB |
Output is correct |
25 |
Correct |
0 ms |
3288 KB |
Output is correct |
26 |
Correct |
0 ms |
3288 KB |
Output is correct |
27 |
Correct |
0 ms |
3288 KB |
Output is correct |
28 |
Correct |
0 ms |
3288 KB |
Output is correct |
29 |
Correct |
0 ms |
3288 KB |
Output is correct |
30 |
Correct |
0 ms |
3288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
3816 KB |
Output is correct |
2 |
Correct |
31 ms |
4476 KB |
Output is correct |
3 |
Correct |
31 ms |
4608 KB |
Output is correct |
4 |
Correct |
12 ms |
3816 KB |
Output is correct |
5 |
Correct |
20 ms |
4212 KB |
Output is correct |
6 |
Correct |
159 ms |
10416 KB |
Output is correct |
7 |
Correct |
162 ms |
10680 KB |
Output is correct |
8 |
Correct |
29 ms |
5004 KB |
Output is correct |
9 |
Correct |
161 ms |
10812 KB |
Output is correct |
10 |
Correct |
157 ms |
9888 KB |
Output is correct |
11 |
Correct |
154 ms |
7644 KB |
Output is correct |
12 |
Correct |
134 ms |
7644 KB |
Output is correct |
13 |
Correct |
149 ms |
7644 KB |
Output is correct |
14 |
Correct |
139 ms |
7644 KB |
Output is correct |
15 |
Correct |
157 ms |
7776 KB |
Output is correct |
16 |
Correct |
137 ms |
7776 KB |
Output is correct |
17 |
Correct |
143 ms |
7776 KB |
Output is correct |
18 |
Correct |
0 ms |
3288 KB |
Output is correct |
19 |
Correct |
145 ms |
7908 KB |
Output is correct |
20 |
Correct |
140 ms |
7908 KB |
Output is correct |
21 |
Correct |
149 ms |
7644 KB |
Output is correct |
22 |
Correct |
151 ms |
7776 KB |
Output is correct |
23 |
Correct |
155 ms |
7908 KB |
Output is correct |
24 |
Correct |
151 ms |
7908 KB |
Output is correct |
25 |
Correct |
107 ms |
7908 KB |
Output is correct |
26 |
Correct |
102 ms |
7908 KB |
Output is correct |
27 |
Correct |
167 ms |
9756 KB |
Output is correct |
28 |
Correct |
169 ms |
9756 KB |
Output is correct |
29 |
Correct |
142 ms |
7908 KB |
Output is correct |
30 |
Correct |
144 ms |
7908 KB |
Output is correct |