QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295514#7514. Clique ChallengeOAleksaWA 1ms7656kbC++142.9kb2023-12-31 09:27:352023-12-31 09:27:36

Judging History

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

  • [2023-12-31 09:27:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7656kb
  • [2023-12-31 09:27:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int N = 1010;
const int mod = 1e9 + 7;
vector<int> g[N];
int n, m, deg[N], del[N], vis[N], id[N];
int dp[1 << 24];
int okL[1 << 24];
int okR[1 << 24];
int add(int x, int y) {
	x += y;
	if (x >= mod)	
		x -= mod;
	return x;
}
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
  int tt = 1;
  //cin >> tt;
  while (tt--) {
    cin >> n >> m;
    for (int i = 1;i <= m;i++) {
    	int x, y;
    	cin >> x >> y;
    	g[x].push_back(y);
    	g[y].push_back(x);
    	deg[x]++;
    	deg[y]++;
    }
    vector<int> order(n);
		iota(order.begin(), order.end(), 1);
		sort(order.begin(), order.end(), [&](int i, int j) {
			return deg[i] < deg[j];
		});
		int ans = 0;
		vector<int> cntL(50), cntR(50);
		vector<int> levo(50), desno(50);
		for (auto x : order) {
			vector<int> all;
			for (auto u : g[x]) {
				if (!del[u]) {
					all.push_back(u);
				}
			}
			del[x] = 1;
			int sz = (int)all.size();
			int l = (sz - 1) / 2;
			int r = sz - l;

			for (int i = 0;i < l;i++) {
				levo[i] = all[i];
				vis[levo[i]] = 1;
				id[levo[i]] = i;
			}
			for (int i = 0;i < r;i++) {
				desno[i] = all[i + l];
				id[desno[i]] = i;
			}
			for (int i = 0;i < l;i++) {
				for (auto u : g[levo[i]]) {
					if (vis[u])
						cntL[i] |= (1 << id[u]);
				}
			}
			for (int mask = 0;mask < (1 << l);mask++) {
				okL[mask] = 1;
				for (int i = 0;i < l;i++) {
					if ((mask & (1 << i)) && (((cntL[i] ^ (1 << i)) & mask) != mask)) {
						okL[mask] = false;
						break;
					}
				}
				dp[mask] = okL[mask];
				if (mask & 1)
					dp[mask] += okL[mask ^ 1];
			}
			for (int i = 1;i < l;i++) {
				for (int mask = 0;mask < (1 << l);mask++) {
					if (mask & (1 << i))
						dp[mask] = add(dp[mask], dp[mask ^ (1 << i)]);
				}
			}
			for (int i = 0;i < l;i++)
				vis[levo[i]] = 0;
			for (int i = 0;i < r;i++) 
				vis[desno[i]] = 1;
			for (int i = 0;i < r;i++) {
				for (auto u : g[desno[i]]) {
					if (vis[u])
						cntR[i] |= (1 << id[u]);
				}
			}
			for (int mask = 0;mask < (1 << r);mask++) {
				okR[mask] = 1;
				for (int i = 0;i < r;i++) {
					if ((mask & (1 << i)) && (((cntR[i] ^ (1 << i)) & mask) != mask)) {
						okR[mask] = false;
						break;
					}
				}
			}
			for (int i = 0;i < r;i++)
				vis[desno[i]] = 0;
			for (int i = 0;i < l;i++) 
				vis[levo[i]] = 1;
			vector<int> gas(r);
			for (int i = 0;i < r;i++) {
				for (auto u : g[desno[i]]) {
					if (vis[u])
						gas[i] |= (1 << id[u]);
				}
			}
			for (int mask = 0;mask < (1 << r);mask++) {
				if (!okR[mask])
					continue;
				int s = (1 << l) - 1;
				for (int i = 0;i < r;i++) {
					if (mask & (1 << i))
						s &= gas[i];
				}
				ans = add(ans, dp[s]);
			}
			for (int i = 0;i < l;i++) {
				vis[levo[i]] = 0;
			}
		}
		cout << ans << '\n';
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7656kb

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7656kb

input:

3 3
1 2
1 3
2 3

output:

7

result:

ok single line: '7'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 7612kb

input:

1000 100
446 789
167 547
254 777
777 185
33 446
777 847
185 877
757 167
72 383
847 446
254 478
959 185
757 446
847 959
959 167
757 847
747 757
446 167
989 757
547 777
33 747
33 254
254 843
33 547
446 980
877 205
185 72
980 959
33 205
877 757
33 847
478 843
757 478
167 877
72 789
877 959
980 478
167 ...

output:

1531

result:

wrong answer 1st lines differ - expected: '1373', found: '1531'