QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#375141 | #7125. Bipartite graph coloring | I_Love_Sonechka# | WA | 0ms | 3640kb | C++14 | 1.9kb | 2024-04-02 21:59:22 | 2024-04-02 21:59:22 |
Judging History
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 j = 0; j < n; ++j) if(used[j]) {
g[i].push_back({j, data[j]});
}
}
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: 100
Accepted
time: 0ms
memory: 3536kb
input:
2 1 1 2 1 2 3 4
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
3 2 1 2 1 0 0 1 2 3 1 0 0 1
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3580kb
input:
6 8 4 2 515760416 192548286 750928404 630204195 4 1 96990010 930195875 743856200 974291870 2 3 916367011 683998013 106243265 629858251 3 1 488938 818633505 75427039 856431926 6 1 825040499 416616900 901278683 182586700 5 1 956237108 946175708 713459401 187609111 2 6 571450128 953143810 29614163 2898...
output:
547881495
result:
wrong answer 1st numbers differ - expected: '875018157', found: '547881495'