QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#166872 | #6865. foreverlasting and fried-chicken | PPP# | AC ✓ | 70ms | 3528kb | C++17 | 1.7kb | 2023-09-06 19:47:07 | 2023-09-06 19:47:08 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod = (int)1e9 + 7;
int mult(int a, int b) {
return (1LL * a * b) % mod;
}
int sub(int a, int b) {
int s = a - b;
if (s < 0) s += mod;
return s;
}
int pw(int a, int b) {
if (b == 0) return 1;
if (b & 1) return mult(a, pw(a, b - 1));
int res = pw(a, b / 2);
return mult(res, res);
}
int sum(int a, int b) {
int s = a + b;
if (s >= mod) s -= mod;
return s;
}
const int maxN = 1005;
typedef bitset<maxN> bs;
bs a[maxN];
int deg[maxN];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
a[i] = 0;
deg[i] = 0;
}
int m;
cin >> m;
while (m--) {
int u, v;
cin >> u >> v;
a[u][v] = a[v][u] = 1;
deg[u]++;
deg[v]++;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == j) continue;
int x = (a[i] & a[j]).count();
ll coef = (1LL * x * (x - 1) * (x - 2) * (x - 3)) / 24;
coef %= mod;
int my_deg = deg[i] - 4;
if (a[i][j]) my_deg--;
coef *= ((1LL * my_deg * (my_deg - 1))) / 2;
coef %= mod;
ans = sum(ans, coef);
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
int tst;
cin >> tst;
while (tst--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 70ms
memory: 3528kb
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