QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#414935 | #7181. Graph Cuts | pandapythoner | WA | 9ms | 4228kb | C++20 | 3.3kb | 2024-05-20 03:52:45 | 2024-05-20 03:52:46 |
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] = v;
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: 100
Accepted
time: 0ms
memory: 3604kb
input:
4 5 1 2 1 3 1 4 2 3 2 4 10 + 1 + 2 ? ? ? ? ? - 2 ? ?
output:
3 2 4 5 0 1 0
result:
ok q=10
Test #2:
score: 0
Accepted
time: 0ms
memory: 3536kb
input:
0 0 0
output:
result:
ok q=0
Test #3:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
0 0 1 ?
output:
0
result:
ok q=1
Test #4:
score: -100
Wrong Answer
time: 9ms
memory: 4228kb
input:
1000 2000 1 50 1 88 331 1 1 352 1 497 2 32 2 282 550 2 989 2 334 3 3 665 4 38 4 69 4 343 4 451 589 4 917 4 89 5 5 162 675 5 681 6 7 22 127 7 7 592 7 672 787 7 8 310 107 9 9 137 184 9 9 244 378 9 446 9 9 658 883 9 65 10 75 10 414 10 10 468 686 10 245 11 269 11 11 386 403 11 493 11 394 12 493 12 565 1...
output:
936 989 1911 867 512 651 1589 1932 62 1482 1521 262 1951 1105 1191 1072 1751 925 768 108 58 953 702 1427 1730 805 1958 1990 1890 5 289 672 1028 1774 416 1834 1000 1003 19 961 1731 1476 1680 1549 210 836 1148 1800 1159 1021 1022 862 543 351 1970 620 1080 1149 1886 194 1768 1927 147 1790 849 1239 905 ...
result:
wrong answer Edge exists, but not found