QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#508740#7181. Graph CutsQingyyxRE 2ms12032kbC++205.2kb2024-08-07 19:45:512024-08-07 19:45:53

Judging History

你现在查看的是最新测评结果

  • [2024-08-07 19:45:53]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:12032kb
  • [2024-08-07 19:45:51]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define enl putchar('\n')
#define all(x) (x).begin(),(x).end()
#define debug(x) printf(" "#x":%d\n",x);
using namespace std;
const int MAXN = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
typedef pair<int, int> pii;
char buf[1 << 21], * p1 = buf, * p2 = buf, obuf[1 << 21], * o = obuf, of[35];
#define gc()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline ll qpow(ll a, ll n) { ll res = 1; while (n) { if (n & 1)res = res * a % mod; n >>= 1; a = a * a % mod; }return res; }
template <class T = int>inline T read() { T s = 0, f = 1; char c = gc(); for (; !isdigit(c); c = gc())if (c == '-')f = -1; for (; isdigit(c); c = gc())s = s * 10 + c - '0'; return s * f; }
inline void read(int* a, int n) { for (int i = 1; i <= n; ++i)a[i] = read(); }
inline char getc() { char c; for (c = gc(); c == ' ' || c == '\n'; c = gc()); return c; }
inline int inal(char* s) { int n = 0; for (s[0] = gc(); !isalpha(s[0]); s[0] = gc()); for (; isalpha(s[n]); s[++n] = gc()); return s[n] = 0, n; }
inline void outd(auto* a, int n) { for (int i = 1; i <= n; ++i)printf("%d ", a[i]); enl; }
int n, m, q;
bitset<MAXN>t[305];
int idg[305][MAXN];
int hav[MAXN], tot, ri[MAXN];
pii g[MAXN];
int deg[MAXN], cnt[MAXN];
const int siz = 300;
bool del[MAXN], inS[MAXN];

struct EG {
    int to, nxt, id;
}e[MAXN << 1];
int head[MAXN], etot;
inline void add(int u, int v, int id) {
    e[etot] = EG {v, head[u], id};
    head[u] = etot++;
}
void clear(int n = MAXN - 1) { memset(head + 1, -1, sizeof(int) * n); etot = 0; }

struct QUE {
    queue<int>q;
    bool inq[MAXN];
    void set(int x) {
        if (inq[x])return;
        q.push(x);
        inq[x] = 1;
    }
    int ask() {
        while (!q.empty()) {
            int u = q.front(); q.pop();
            inq[u] = 0;
            if (cnt[u] == 1)return u;
        }
        return 0;
    }
}que;



void solve() {
    n = read(), m = read();
    for (int i = 1; i <= m; ++i) {
        int x = read(), y = read();
        g[i] = {x, y};
        deg[x]++, deg[y]++;
    }
    for (int i = 1; i <= n; ++i)
        if (deg[i] >= siz)
            ri[hav[i] = ++tot] = i;

    clear(n);
    for (int i = 1; i <= m; ++i) {
        auto& [u, v] = g[i];
        if (!hav[u] && !hav[v]) {
            add(u, v, i), add(v, u, i);
        } else {
            if (hav[u])idg[hav[u]][v] = i, t[hav[u]].set(v);
            if (hav[v])idg[hav[v]][u] = i, t[hav[v]].set(u);
        }
    }

    del[0] = 1;

    q = read();
    while (q--) {
        char op = getc();
        if (op == '+') {
            int x = read();
            inS[x] = 1;
            for (int i = 1; i <= tot; ++i)
                if (!del[idg[i][x]])
                    t[i].reset(x);
            if (!hav[x]) {
                while (~head[x] && del[e[head[x]].id])
                    head[x] = e[head[x]].nxt;
                for (int i = head[x], pre = i; ~i; pre = i, i = e[i].nxt) {
                    if (del[e[i].id]) {
                        e[pre].nxt = e[i].nxt;
                        continue;
                    }
                    cnt[e[i].id]++;
                    if (cnt[e[i].id] == 1)
                        que.set(e[i].id);
                }
            }
        } else if (op == '-') {
            int x = read();
            inS[x] = 0;
            for (int i = 1; i <= tot; ++i)
                if (!del[idg[i][x]])
                    t[i].set(x);
            if (!hav[x]) {
                while (~head[x] && del[e[head[x]].id])
                    head[x] = e[head[x]].nxt;
                for (int i = head[x], pre = i; ~i; pre = i, i = e[i].nxt) {
                    if (del[e[i].id]) {
                        e[pre].nxt = e[i].nxt;
                        continue;
                    }
                    cnt[e[i].id]--;
                    if (cnt[e[i].id] == 1)
                        que.set(e[i].id);
                }
            }
        } else {
            int ans = que.ask();
            if (!ans) {
                for (int i = 1; i <= tot; ++i) {
                    if (!inS[ri[i]])continue;
                    int pos = t[i]._Find_first();
                    if (pos != t[i].size()) {
                        t[i].reset(pos);
                        if (hav[pos])
                            t[hav[pos]].reset(ri[i]);
                        ans = idg[i][pos];
                        break;
                    }
                }
            }
            del[ans] = 1;
            printf("%d\n", ans);
        }
        // for (int i = 1; i <= tot; ++i)
        //     cout << t[i] << '\n';
        // cout << '\n';
    }
}
signed main(signed argc, char const* argv[]) {
    clock_t c1 = clock();
#ifdef LOCAL
    freopen("in.in", "r", stdin);
    freopen("out.out", "w", stdout);
#endif
    //=============================================================
    int TxT = 1;
    // TxT = read();
    while (TxT--)
        solve();
    //=============================================================
#ifdef LOCAL
    end :
    cerr << "Time Used:" << clock() - c1 << "ms" << endl;
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 10284kb

input:

4 5
1 2
1 3
1 4
2 3
2 4
10
+ 1
+ 2
?
?
?
?
?
- 2
?
?

output:

3
2
5
4
0
1
0

result:

ok q=10

Test #2:

score: 0
Accepted
time: 1ms
memory: 10040kb

input:

0 0
0

output:


result:

ok q=0

Test #3:

score: 0
Accepted
time: 1ms
memory: 9940kb

input:

0 0
1
?

output:

0

result:

ok q=1

Test #4:

score: 0
Accepted
time: 2ms
memory: 12032kb

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:

1546
1161
936
990
989
987
986
1911
1979
1828
1266
1176
867
512
653
651
405
1816
1542
847
1933
1589
1277
674
1567
1482
398
62
1521
1520
269
265
264
263
262
1951
1109
495
1191
334
1751
925
218
1581
768
555
1776
108
59
58
953
275
702
1461
1427
1240
1990
1958
779
1837
1128
935
1550
5
1
1989
591
590
589
...

result:

ok q=100000

Test #5:

score: -100
Runtime Error

input:

447 99681
2 1
1 3
4 1
1 5
1 6
1 7
1 8
9 1
10 1
1 11
1 12
1 13
1 14
1 15
1 16
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
1 26
27 1
28 1
1 29
30 1
31 1
1 32
33 1
1 34
1 35
36 1
37 1
38 1
39 1
40 1
1 41
1 42
43 1
44 1
45 1
46 1
1 47
48 1
49 1
1 50
1 51
1 52
53 1
54 1
55 1
1 56
57 1
1 58
59 1
60 1
1 6...

output:


result: