QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#648446 | #9449. New School Term | xh_team# | WA | 0ms | 3596kb | C++20 | 1.3kb | 2024-10-17 19:01:42 | 2024-10-17 19:01:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
n *= 2;
vector<pair<int, int>> edges(m);
for (auto &[x, y] : edges) {
cin >> x >> y;
x--, y--;
}
vector<int> par(n), h(n), c(n);
iota(par.begin(), par.end(), 0);
function<int(int)> find = [&](int x) {
return x == par[x] ? x : find(par[x]);
};
vector<vector<int>> adj(n);
function<void(int, int, int)> dfs = [&](int x, int pre, int o) {
c[x] ^= o;
for (int y : adj[x]) {
if (y != pre) {
dfs(y, x, o);
}
}
};
auto merge = [&](int x, int y) {
int o = c[x] ^ c[y] ^ 1;
x = find(x);
y = find(y);
adj[x].push_back(y);
adj[y].push_back(x);
if (h[x] >= h[y]) {
par[y] = x;
dfs(y, x, o);
if (h[x] == h[y]) {
h[x] += 1;
}
} else {
par[x] = y;
dfs(x, y, o);
}
};
for (int i = m - 1; i >= 0; i--) {
auto [x, y] = edges[i];
if (find(x) != find(y)) {
merge(x, y);
}
}
for (int i = 0; i < n; i++) {
cout << c[i];
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3596kb
input:
2 4 1 3 2 4 1 4 1 2
output:
0111
result:
wrong answer The number of 0s must be equal to that of 1s.