#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5001;
const int MOD = 1e4+7;
int deg[MAXN], cnt[MAXN], fact[MAXN];
int fastPow(int a, int b) {
if (b == 0) return 1;
if (b & 1) return (a * fastPow(a, b-1)) % MOD;
return fastPow((a*a)%MOD, b/2);
}
int rev(int a) {
return fastPow(a, MOD-2);
}
int choose(int a, int b) {
return (((fact[a]*rev(fact[a-b])) % MOD) * rev(fact[b])) % MOD;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
fact[0] = 1;
for (int i = 1; i<MAXN; ++i) fact[i] = (i*fact[i-1]) % MOD;
int n, m = 0; cin >> n;
for (int i = 0; i<n; ++i) {
int sz,a; cin >> sz;
deg[i] = sz; ++cnt[sz];
m += sz;
while (sz--) {
cin >> a;
}
}
m /= 2;
sort(deg,deg+n);
int same = 1, degSum = 0, x = 1, ans = 0;
for (int i = n-1; i; --i, ++x) {
if (i != n-1) {
if (deg[i] == deg[i+1]) ++same;
else same = 1;
}
degSum += deg[i];
if (degSum - (x*(x-1))/2 == m) {
ans += choose(cnt[deg[i]], same);
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
352 KB |
Output is correct |
2 |
Correct |
1 ms |
356 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
620 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
608 KB |
Output is correct |
2 |
Correct |
30 ms |
2792 KB |
Output is correct |
3 |
Correct |
145 ms |
10432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
860 KB |
Output is correct |
2 |
Correct |
37 ms |
3508 KB |
Output is correct |
3 |
Correct |
178 ms |
14216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
2916 KB |
Output is correct |
2 |
Correct |
87 ms |
7364 KB |
Output is correct |
3 |
Correct |
315 ms |
22544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
4236 KB |
Output is correct |
2 |
Correct |
204 ms |
11040 KB |
Output is correct |
3 |
Correct |
720 ms |
35292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
473 ms |
24168 KB |
Output is correct |
2 |
Correct |
315 ms |
16140 KB |
Output is correct |
3 |
Correct |
1101 ms |
55892 KB |
Output is correct |
4 |
Correct |
1190 ms |
117128 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |