QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#449993#6874. LeshphonAcoippWA 1121ms3664kbC++141.8kb2024-06-21 22:07:502024-06-21 22:07:50

Judging History

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

  • [2024-06-21 22:07:50]
  • 评测
  • 测评结果:WA
  • 用时:1121ms
  • 内存:3664kb
  • [2024-06-21 22:07:50]
  • 提交

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_popcount(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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1121ms
memory: 3664kb

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:

217223
162991
769
0
887757
2808
1345600
6726
5621725
39580791

result:

wrong answer 1st lines differ - expected: '159936', found: '217223'