QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#449994 | #6874. Leshphon | Acoipp | AC ✓ | 1120ms | 3660kb | C++14 | 1.8kb | 2024-06-21 22:08:38 | 2024-06-21 22:08:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define PII pair<int, int>
const int N = 60;
int n, m;
LL d[N], d1[N], k[N], ans;
int q[N], tt;
bool work(vector<PII> &s)
{
q[tt = 1] = 1;
LL flag = 1 << 1;
while(tt)
{
int t = q[tt--];
LL p = d[t] ^ (d[t] & flag);
flag |= d[t];
while(p)
{
int num = __builtin_ctzll(p & -p);
p ^= p & -p;
s.push_back({t, num}), q[++tt] = num;
}
}
if(flag != (1ll << n + 1) - 2) return false;
q[tt = 1] = 1, flag = 1 << 1;
while(tt)
{
int t = q[tt--];
LL p = d1[t] ^ (d1[t] & flag);
flag |= d1[t];
while(p)
{
int num = __builtin_ctzll(p & -p);
p ^= p & -p;
s.push_back({num, t}), q[++tt] = num;
}
}
if(flag != (1ll << n + 1) - 2) return false;
return true;
}
void dfs(int x)
{
vector<PII> s, s1;
if(!work(s))
{
LL cnt = m;
for(int i = 1; i <= n; i++)
cnt -= __builtin_popcountll(k[i]);
if(x == 1) ans += cnt * (cnt - 1) * (cnt - 2) / 6;
else if(x == 2) ans += cnt * (cnt - 1) / 2;
else if(x == 3) ans += cnt;
else ans++;
return;
}
if(x == 4) return;
for(PII i : s)
if(k[i.first] >> i.second & 1 ^ 1)
{
d[i.first] ^= 1ll << i.second, d1[i.second] ^= 1ll << i.first;
k[i.first] ^= 1ll << i.second;
s1.push_back(i);
dfs(x + 1);
d[i.first] ^= 1ll << i.second, d1[i.second] ^= 1ll << i.first;
}
for(PII i : s1) k[i.first] ^= 1ll << i.second;
}
int main()
{
int T;
cin >> T;
while(T--)
{
memset(d, 0, sizeof(d));
memset(d1, 0, sizeof(d1));
memset(k, 0, sizeof(k));
ans = 0;
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
int a, b;
scanf("%d%d", &a, &b);
d[a] |= 1ll << b, d1[b] |= 1ll << a;
}
dfs(1);
cout << ans << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1120ms
memory: 3660kb
input:
10 50 145 1 6 1 33 1 38 2 11 2 29 2 36 2 42 3 20 3 35 3 36 4 39 5 39 6 10 6 23 6 27 6 34 6 39 6 45 6 47 7 24 7 37 8 14 8 47 9 3 9 40 10 5 10 12 10 25 11 14 11 18 12 13 12 44 13 38 14 38 15 4 15 29 15 31 15 36 15 44 16 17 16 35 17 18 17 50 18 3 18 19 18 20 18 27 19 31 20 22 20 31 21 8 21 22 21 27 21 ...
output:
159936 126858 722 0 833992 2756 1263249 6657 5531904 38194324
result:
ok 10 lines