QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#321946 | #7125. Bipartite graph coloring | Tobo | WA | 1ms | 3592kb | C++20 | 2.5kb | 2024-02-05 22:51:05 | 2024-02-05 22:51:05 |
Judging History
answer
#include <bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> s;
using i64 = long long;
// using u32 = unsigned int;
// using u64 = unsigned long long;
// using i128 = __int128_t;
using namespace std;
const int N = 2e5 + 5;
// const int B = 455;
// const int M = 2e6 + 5;
// const int base = 13131;
// const int base = 17171;
// const int mod = 998244353;
const int mod = 1e9 + 7;
// const i64 mod = 1000000000000000003LL;
// const double pi = acos(-1);
void solve()
{
int n, m;
cin >> n >> m;
vector<vector<array<int, 5>>> adj(n);
for (int i = 0, a, b, c, d, e, f; i < m; i++)
{
cin >> a >> b >> c >> d >> e >> f;
a--, b--;
adj[a].push_back({b, c, d, e, f});
adj[b].push_back({a, c, d, e, f});
}
vector<int> col(n, -1);
auto dfs1 = [&](auto &dfs1, int cur) -> void
{
for (auto [i, c, d, e, f] : adj[cur])
{
if (col[i] == -1)
{
col[i] = col[cur] ^ 1;
dfs1(dfs1, i);
}
}
};
for (int i = 0; i < n; i++)
if (col[i] == -1)
col[i] = 1, dfs1(dfs1, i);
vector<vector<int>> num(2);
for (int i = 0; i < n; i++)
num[col[i]].push_back(i);
if (num[0].size() > num[1].size())
swap(num[0], num[1]);
vector<vector<int>> val(2, vector<int>(n, 1));
int ans = 0;
auto dfs2 = [&](auto &dfs2, int cur) -> void
{
if (cur == num[0].size())
{
int tmp = 1;
for (int i : num[1])
tmp = (i64)tmp * (val[0][i] + val[1][i]) % mod;
ans = (ans + tmp) % mod;
return;
}
auto tmp = val;
for (auto [i, c, d, e, f] : adj[num[0][cur]])
val[0][i] = (i64)val[0][i] * c % mod,
val[1][i] = (i64)val[1][i] * d % mod;
dfs2(dfs2, cur + 1);
val = tmp;
for (auto [i, c, d, e, f] : adj[num[0][cur]])
val[0][i] = (i64)val[0][i] * e % mod,
val[1][i] = (i64)val[1][i] * f % mod;
dfs2(dfs2, cur + 1);
val = tmp;
};
dfs2(dfs2, 0);
cout << ans << '\n';
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
cout << fixed << setprecision(10);
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3592kb
input:
2 1 1 2 1 2 3 4
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3508kb
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: 1ms
memory: 3552kb
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:
258013063
result:
wrong answer 1st numbers differ - expected: '875018157', found: '258013063'