QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153273#6865. foreverlasting and fried-chickenneko_nyaaAC ✓483ms3788kbC++231.1kb2023-08-29 19:49:322023-08-29 19:49:32

Judging History

你现在查看的是最新测评结果

  • [2023-08-29 19:49:32]
  • 评测
  • 测评结果:AC
  • 用时:483ms
  • 内存:3788kb
  • [2023-08-29 19:49:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int M = 1000000007;
int modpow(int n, int k) {
	int ans = 1;
	while (k) {
		if (k % 2) ans = (ans*n) % M;
		n = (n*n) % M; k /= 2;
	}
	return ans;
}

int c4(int n) {
	int p = n*(n-1)*(n-2)*(n-3) % M;
	int q = 1*2*3*4;
	return p*modpow(q, M-2) % M;
}

int c2(int n) {
	int p = n*(n-1);
	int q = 1*2;
	return p*modpow(q, M-2) % M;
}

typedef bitset<1000> bs;

void solve() {
	int n, m; cin >> n >> m;
	vector<bs> adj(n);

	while (m--) {
		int x, y; cin >> x >> y; x--, y--;
		adj[x][y] = adj[y][x] = 1;
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) continue;

			int up = adj[i].count();
			int down = (adj[i] & adj[j]).count();
			if (adj[i][j]) up--;

			if (up < 6 || down < 4) continue;
			int tmp = c4(down);
			tmp = (tmp*c2(up-4)) % M;

			ans = (ans+tmp) % M;
		}
	}
	cout << ans << '\n';
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);

	int t; cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 483ms
memory: 3788kb

input:

9
8 10
1 2
1 3
1 4
1 5
1 6
1 7
8 4
8 5
8 6
8 7
10 12
1 2
1 3
1 4
1 5
1 6
1 7
8 4
8 5
8 6
8 7
8 9
8 10
11 13
1 2
1 3
1 4
1 5
1 6
1 7
8 4
8 5
8 6
8 7
8 9
8 10
1 11
11 14
1 2
1 3
1 4
1 5
1 6
1 7
8 4
8 5
8 6
8 7
8 9
8 10
1 11
1 8
10 45
5 10
2 9
5 8
3 10
2 10
4 9
4 3
4 2
5 6
7 1
10 6
10 7
6 1
8 3
5 1
7 5...

output:

1
2
4
4
37800
0
278229818
23929419
3268272

result:

ok 9 lines