QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#295478#7514. Clique ChallengeOAleksaWA 1ms7936kbC++142.8kb2023-12-31 08:31:332023-12-31 08:31:34

Judging History

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

  • [2023-12-31 08:31:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7936kb
  • [2023-12-31 08:31:33]
  • 提交

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 cntL[N], cntR[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);
					cntL[u] = cntR[u] = 0;
				}
			}
			int sz = (int)all.size();
			int l = sz / 2;
			int r = sz - l;
			vector<int> levo, desno;
			for (int i = 0;i < l;i++) {
				vis[all[i]] = 1;
				levo.push_back(all[i]);
				id[all[i]] = i;
			}
			for (int i = 0;i < r;i++)
				desno.push_back(all[i + l]);
			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;
					}
				}
				dp[mask] = okL[mask];
				if (mask & 1)
					dp[mask] += dp[mask ^ 1];
				for (int i = 1;i < l;i++) {
					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;
				id[desno[i]] = 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;
				}
			}
			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++) 
					s &= gas[i];
				ans = add(ans, dp[s]);
			}
			for (auto u : all) {
				vis[u] = 0;
			}
			del[x] = 1;
		}
		cout << ans << '\n';
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7688kb

input:

3 2
1 2
2 3

output:

5

result:

ok single line: '5'

Test #2:

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

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: 7936kb

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:

1041

result:

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