QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414937 | #7181. Graph Cuts | pandapythoner | WA | 0ms | 3612kb | C++20 | 3.3kb | 2024-05-20 03:56:55 | 2024-05-20 03:56:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
const ll inf = 1e18;
mt19937 rnd(234);
struct edge {
int to;
int i;
};
int n, m;
vector<vector<edge>> g;
int q;
vector<int> a;
vector<int> rs;
vector<int> usd, usde;
vector<int> clr;
vector<int> p;
vector<int> pe;
vector<array<vector<int>, 2>> sns;
queue<int> que;
void dfs(int v) {
usd[v] = true;
for (auto [to, i] : g[v]) {
if (usd[to] or usde[i]) {
continue;
}
usde[i] = true;
p[to] = v;
pe[to] = i;
sns[v][0].push_back(to);
dfs(to);
}
}
void solve() {
rs.assign(q, -1);
usde.assign(m, false);
while (1) {
usd.assign(n, false);
p.assign(n, -1);
pe.assign(n, -1);
sns.assign(n, array<vector<int>, 2>({ vector<int>({}), vector<int>({}) }));
clr.assign(n, 0);
que = {};
bool fndd = false;
for (int v = 0; v < n; v += 1) {
if (usd[v]) {
fndd = true;
continue;
}
dfs(v);
}
if (!fndd) {
break;
}
for (int i = 0; i < q; i += 1) {
if (a[i] == -1) {
if (rs[i] != -1) {
continue;
}
while (!que.empty()) {
int v = que.front();
que.pop();
bool fndd = false;
while (!sns[v][clr[v] ^ 1].empty()) {
int to = sns[v][clr[v] ^ 1].back();
sns[v][clr[v] ^ 1].pop_back();
if (clr[to] == clr[v] ^ 1 and p[to] == v) {
fndd = true;
rs[i] = pe[to];
p[to] = -1;
pe[to] = -1;
break;
}
}
if (fndd) {
break;
}
}
} else {
int v = a[i];
clr[v] ^= 1;
que.push(v);
if (p[v] != -1) {
sns[p[v]][clr[v]].push_back(v);
que.push(p[v]);
}
}
}
}
}
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
cin >> n >> m;
g.assign(n, vector<edge>());
for (int i = 0; i < m; i += 1) {
int u, v;
cin >> u >> v;
--u;
--v;
g[u].push_back(edge{ v, i });
g[v].push_back(edge{ u, i });
}
cin >> q;
a.resize(q);
for (int i = 0; i < q; i += 1) {
char c;
cin >> c;
if (c == '+' or c == '-') {
int x;
cin >> x;
--x;
a[i] = x;
} else if (c == '?') {
a[i] = -1;
}
}
solve();
for (int i = 0; i < q; i += 1) {
if (a[i] == -1) {
cout << rs[i] + 1 << "\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3612kb
input:
4 5 1 2 1 3 1 4 2 3 2 4 10 + 1 + 2 ? ? ? ? ? - 2 ? ?
output:
5 3 0 0 0 1 0
result:
wrong answer Edge exists, but not found