QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295512#7514. Clique ChallengeOAleksaRE 0ms0kbC++142.9kb2023-12-31 09:24:392023-12-31 09:24:40

Judging History

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

  • [2023-12-31 09:24:40]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-12-31 09:24:39]
  • 提交

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;
		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 - 2) / 2;
			int r = sz - l;
			vector<int> cntL(l), cntR(r);
			vector<int> levo(l), desno(r);
			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: 0
Runtime Error

input:

3 2
1 2
2 3

output:


result: