Submission #18973

# Submission time Handle Problem Language Result Execution time Memory
18973 2016-02-16T23:16:23 Z tncks0121 트리 (kriii4_X) C++14
100 / 100
155 ms 11080 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <time.h>
#include <functional>
#include <numeric>
#include <iostream>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

#define debug(format, ...) printf(format, __VA_ARGS__);

const int N_ = (int)1e9 + 10;
const int M_ = (int)1e5 + 10;

const ll MOD = (ll)1e9 + 7;

ll modpow (ll a, ll b) {
	a %= MOD;
	ll ret = 1;
	while(b > 0) {
		if(b & 1) ret = (ret * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return ret;
}

struct mint {
	ll val;
	mint(ll val = 0): val((val % MOD + MOD) % MOD) { }
	mint operator+(mint p) { return val + p.val; }
	mint operator-(mint p) { return val - p.val; }
	mint operator*(mint p) { return val * p.val; }
	mint operator/(mint p) { return val * modpow(p.val, MOD-2); }
};

int N, M;

unordered_map<int, int> grp, sz;

int get_grp (int x) {
	if(grp.count(x) == 0) grp[x] = x, sz[x] = 1;
	if(grp[x] == x) return x;
	return grp[x] = get_grp(grp[x]);
}

int deg[100];
int tmp[100];

void brute (int x, int sum) {
	if(x > N-M) {
		for(int i =1; i<= N-M;i++) printf("%d ", tmp[i]+1);
		puts("");
		return;
	}
	for(int cur = 0; cur + sum <= N-M-2; cur++) {
		if(x == N-M) cur = N-M-2-sum;
		tmp[x] = cur;
		brute(x+1, sum+cur);
		tmp[x] = 0;
	}
}

int main() {
	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; i++) {
		int u, v; scanf("%d%d", &u, &v);

		int a = get_grp(u);
		int b = get_grp(v);
		if(a == b)
			return 0 & puts("0");

		if(rand() & 1) swap(a, b);
		grp[a] = b;
		sz[b] += sz[a];
		sz.erase(a);
	}

	mint ans;

	if(M == N-1) {
		ans = 1;
	}else {
		ans = modpow(N, N - M - 2);
		for(auto it : sz) ans = ans * it.second;	
	}

	printf("%lld\n", ans.val);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1728 KB Output is correct
2 Correct 0 ms 1728 KB Output is correct
3 Correct 0 ms 1728 KB Output is correct
4 Correct 0 ms 1728 KB Output is correct
5 Correct 0 ms 1728 KB Output is correct
6 Correct 0 ms 1728 KB Output is correct
7 Correct 0 ms 1728 KB Output is correct
8 Correct 0 ms 1728 KB Output is correct
9 Correct 0 ms 1728 KB Output is correct
10 Correct 0 ms 1728 KB Output is correct
11 Correct 0 ms 1728 KB Output is correct
12 Correct 0 ms 1728 KB Output is correct
13 Correct 0 ms 1728 KB Output is correct
14 Correct 0 ms 1728 KB Output is correct
15 Correct 0 ms 1728 KB Output is correct
16 Correct 0 ms 1728 KB Output is correct
17 Correct 0 ms 1728 KB Output is correct
18 Correct 0 ms 1728 KB Output is correct
19 Correct 0 ms 1728 KB Output is correct
20 Correct 0 ms 1728 KB Output is correct
21 Correct 0 ms 1728 KB Output is correct
22 Correct 0 ms 1728 KB Output is correct
23 Correct 0 ms 1728 KB Output is correct
24 Correct 0 ms 1728 KB Output is correct
25 Correct 0 ms 1728 KB Output is correct
26 Correct 0 ms 1728 KB Output is correct
27 Correct 0 ms 1728 KB Output is correct
28 Correct 0 ms 1728 KB Output is correct
29 Correct 0 ms 1728 KB Output is correct
30 Correct 0 ms 1728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2264 KB Output is correct
2 Correct 28 ms 2780 KB Output is correct
3 Correct 33 ms 2916 KB Output is correct
4 Correct 9 ms 2256 KB Output is correct
5 Correct 19 ms 2780 KB Output is correct
6 Correct 152 ms 10732 KB Output is correct
7 Correct 132 ms 10844 KB Output is correct
8 Correct 34 ms 3856 KB Output is correct
9 Correct 129 ms 11080 KB Output is correct
10 Correct 141 ms 10416 KB Output is correct
11 Correct 147 ms 5912 KB Output is correct
12 Correct 133 ms 5912 KB Output is correct
13 Correct 147 ms 5904 KB Output is correct
14 Correct 125 ms 5908 KB Output is correct
15 Correct 137 ms 5900 KB Output is correct
16 Correct 128 ms 6104 KB Output is correct
17 Correct 141 ms 6100 KB Output is correct
18 Correct 0 ms 1728 KB Output is correct
19 Correct 143 ms 6148 KB Output is correct
20 Correct 155 ms 6020 KB Output is correct
21 Correct 134 ms 5904 KB Output is correct
22 Correct 136 ms 6028 KB Output is correct
23 Correct 128 ms 6148 KB Output is correct
24 Correct 145 ms 6140 KB Output is correct
25 Correct 90 ms 6972 KB Output is correct
26 Correct 95 ms 6972 KB Output is correct
27 Correct 134 ms 10408 KB Output is correct
28 Correct 149 ms 10400 KB Output is correct
29 Correct 131 ms 6140 KB Output is correct
30 Correct 135 ms 6136 KB Output is correct