QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375208#7125. Bipartite graph coloringI_Love_Sonechka#WA 0ms3540kbC++142.9kb2024-04-02 23:36:032024-04-02 23:36:04

Judging History

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

  • [2024-04-02 23:36:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3540kb
  • [2024-04-02 23:36:03]
  • 提交

answer

#include <bits/stdc++.h>
#include <math.h>
			
using namespace std;

// c++ short types
#define Int long long
#define vt vector

const int mod = 1e9 + 7;
void add(int &a, int b) {
	a += b;
	if(a >= mod) { 
		a -= mod;
	}
	if(a < 0) {
		a += mod;
	}
}
int mul(int a, int b) {
	return a * 1ll * b % mod;
}

bool debug = true;

void solver() {
	int n, m;
	if(debug) {
		n = 4; m = rand() % 10 + 1;
	} else {
		cin >> n >> m;
	}
	vt<vt<pair<int, vt<int>>>> g(n);
	vt<vt<int>> zzz;
	for(int i = 0; i < m; ++i) {
		int a, b;
		vt<int> v(4);
		if(debug) {
			a = rand() % n /2, b = rand() % n / 2 + n/ 2;
			for(auto &x: v) {
				x = rand() % 2;
			}
		} else {
			cin >> a >> b;
			--a, --b;
			for(auto &x: v) {
				cin >> x;
			}
		}
		g[a].push_back({b, v});
		swap(v[1], v[2]);
		g[b].push_back({a, v});
		zzz.push_back({a,b});
		for(auto y : v) {
			zzz.back().push_back(y);
		}
	}
	for(int i = 0; i < n; ++i) {
		vt<vt<int>> data(n, vt<int>(4, 1));
		vt<int> used(n, 0);
		for(auto [to, v]: g[i]) {
			for(int j = 0; j < 4; ++j) {
				data[to][j] = mul(data[to][j], v[j]);
			}
			assert(used[to] == 0);
			used[to] = 1;
		}
		g[i].clear();
		for(int j = 0; j < n; ++j) if(used[j]) {
			g[i].push_back({j, data[j]});
		}
	}
	auto Brute = [&]() -> int {
		int res = 0;
		vt<vt<int>> used(n, vt<int>(n, false));
		vt<vt<int>> data, edges;
		for(int i = 0; i < n; ++i) {
			for(auto [to, v]: g[i]) if(!used[to][i]) {
				used[to][i] = used[i][to] = 1;
				edges.push_back({i, to});
				data.push_back(v);
			}
		}
		for(int mask = 0; mask < (1<<n); ++mask) {
			int local = 1;
			for(int i = 0; i < (int)edges.size(); ++i) {
				int a = edges[i][0], b = edges[i][1];
				auto v = data[i];
				local = mul(local, v[(mask >> a & 1)*2+(mask>>b&1)]);
			}
			add(res, local);
		}
		return res;
	};
	vt<vt<int>> part(2);
	vt<int> cl(n, -1);
	auto Dfs = [&](auto self, int e, int c) -> void {
		if(cl[e] != -1) {
			assert(cl[e] == c);
			return ;
		}
		part[c].push_back(e);
		cl[e] = c;
		for(auto [to, v]: g[e]) {
			self(self, to, !c);
		}
	};
	for(int i = 0; i < n; ++i) if(cl[i] == -1) {
		Dfs(Dfs, i, 0);
	}
	if(part[0].size() < part[1].size()) {
		swap(part[0], part[1]);
	}
	vt<int> ids(n);
	for(int i = 0; i < part[1].size(); ++i) {
		ids[part[1][i]] = i;
	}
	assert(part[1].size() <= 20);
	int res = 0;
	for(int mask = 0; mask < (1<<part[1].size()); ++mask) {
		int local = 1;
		for(int i: part[0]) {
			vt<int> val(2, 1);
			for(int j = 0; j < 2; ++j) {
				for(auto [to, v]: g[i]) {
					val[j] = mul(val[j], v[j*2+((mask>>ids[to])&1)]);
				}
			}
			add(val[0], val[1]);
			local = mul(local, val[0]);
		}
		add(res, local);
	}
	cout << res << "\n";
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int tt = 1;
	cin >> tt;
	for(int t = 0; t < tt; ++t) {
    solver();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3540kb

input:

2 1
1 2 1 2 3 4

output:

0
12

result:

wrong answer 1st numbers differ - expected: '10', found: '0'