QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#375136#7125. Bipartite graph coloringI_Love_Sonechka#WA 1ms3640kbC++141.9kb2024-04-02 21:57:462024-04-02 21:58:22

Judging History

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

  • [2024-04-02 21:58:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3640kb
  • [2024-04-02 21:57:46]
  • 提交

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

void solver() {
	int n, m; cin >> n >> m;
	vt<vt<pair<int, vt<int>>>> g(n);
	for(int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		vt<int> v(4);
		for(auto &x: v) {
			cin >> x;
		}
		g[--a].push_back({--b, v});
		g[b].push_back({a, v});
		swap(g[b].back().second[1], g[b].back().second[2]);
	}
	for(int i = 0; i < n; ++i) {
		vt<vt<int>> data(n, vt<int>(4, 1));
		vt<int> used(n, -1);
		for(auto [to, v]: g[i]) {
			for(int j = 0; j < 4; ++j) {
				data[to][j] = mul(data[to][j], v[j]);
			}
			used[to] = 1;
		}
		g[i].clear();
		for(int i = 0; i < n; ++i) if(used[i]) {
			g[i].push_back({i, data[i]});
		}
	}
	vt<vt<int>> part(2);
	vt<int> cl(n, -1);
	auto Dfs = [&](auto self, int e, int c) -> void {
		if(cl[e] != -1) {
			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) {
		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(m);
	int res = 0;
	for(int mask = 0; mask < (1<<part[1].size()); ++mask) {
		int local = 1;
		for(int i: part[0]) if(!g[i].empty()) {
			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;
	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: 1ms
memory: 3640kb

input:

2 1
1 2 1 2 3 4

output:

12

result:

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