QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#508748#7181. Graph CutsQingyyxTL 2408ms195608kbC++205.2kb2024-08-07 19:50:132024-08-07 19:50:13

Judging History

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

  • [2024-08-07 19:50:13]
  • 评测
  • 测评结果:TL
  • 用时:2408ms
  • 内存:195608kb
  • [2024-08-07 19:50:13]
  • 提交

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[505];
int idg[505][MAXN];
int hav[MAXN], tot, ri[MAXN];
pii g[MAXN];
int deg[MAXN], cnt[MAXN];
const int siz = 400;
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;
}

详细

Test #1:

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

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: 10068kb

input:

0 0
0

output:


result:

ok q=0

Test #3:

score: 0
Accepted
time: 0ms
memory: 9944kb

input:

0 0
1
?

output:

0

result:

ok q=1

Test #4:

score: 0
Accepted
time: 5ms
memory: 12092kb

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: 0
Accepted
time: 67ms
memory: 194492kb

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:

6

result:

ok q=100000

Test #6:

score: 0
Accepted
time: 132ms
memory: 195608kb

input:

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

output:

70
44
489
933
1376
1818
2259
2699
3138
3576
21
466
5
450
894
1337
1779
2221
2222
2223
3
448
892
1336
1338
1339
1340
2
447
1
4
6
7
8
9
10
12
13
14
15
16
17
18
19
20
24
25
26
27
28
29
30
31
32
33
34
35
36
38
45
48
49
51
40
52
54
55
37
41
57
58
59
60
61
62
63
64
65
66
67
68
71
72
75
77
78
81
42
82
83
8...

result:

ok q=100000

Test #7:

score: 0
Accepted
time: 352ms
memory: 194500kb

input:

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

output:

180
25
1
447
448
449
450
451
452
453
454
455
456
457
459
460
461
462
463
464
465
466
467
469
471
472
473
474
475
476
477
8
897
1340
1782
2223
2663
3102
3541
3542
3543
3544
3546
3547
3548
3549
3550
3551
3552
3554
7
3556
3557
3559
470
478
480
481
483
484
486
487
488
489
490
491
492
493
494
495
496
497...

result:

ok q=100000

Test #8:

score: 0
Accepted
time: 740ms
memory: 194264kb

input:

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

output:

0
84
529
27
472
916
1359
1801
20
465
909
1352
1794
2235
2675
3114
3552
3989
4425
4860
5294
5727
6159
6590
7020
7449
7877
8304
8731
8732
8733
8734
8735
8736
8738
8739
8741
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
1
2
3
4
5
6
7
8
9
10
12
13
14
15
1...

result:

ok q=100000

Test #9:

score: 0
Accepted
time: 1404ms
memory: 194304kb

input:

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

output:

0
0
0
0
0
0
0
0
81
526
970
1413
1855
2296
2736
3175
3613
4050
4486
4921
5355
5788
6220
6651
7081
7510
7938
8365
8791
9216
9640
10063
10485
10906
11326
11745
12163
12580
12996
13411
13825
14238
14650
15061
15471
15880
16288
16695
17101
17506
17910
43
488
932
1375
1817
2258
2698
3137
3575
4012
4448
48...

result:

ok q=100000

Test #10:

score: 0
Accepted
time: 2408ms
memory: 190540kb

input:

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

output:

0
0
0
0
173
618
1062
1505
1947
2388
2828
3267
3705
4142
4578
5013
5447
5880
48
493
937
1380
1822
2263
2703
3142
3580
4017
4453
4888
5322
5755
6187
6618
7048
7477
7905
8332
8758
9183
9607
10030
10452
10873
11293
11712
12130
12547
12963
13378
13792
14205
14617
15028
15438
15847
16255
16662
17068
17473...

result:

ok q=100000

Test #11:

score: 0
Accepted
time: 45ms
memory: 190360kb

input:

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

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok q=100000

Test #12:

score: 0
Accepted
time: 72ms
memory: 194664kb

input:

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

output:

2

result:

ok q=100000

Test #13:

score: 0
Accepted
time: 126ms
memory: 190756kb

input:

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

output:

5
9
10
11
12
15
16
17
20
21
23
25
31
33
35
42
43
50
52
53
58
1
450
456
2
447
894
900
896
901
904
905
906
909
910
908
911
914
916
892
920
922
924
4
449
893
1336
1780
1337
1779
2221
2222
2226
2227
2230
2234
2235
2236
2237
2240
2242
2245
2246
2248
2250
2224
2253
2257
2264
2265
2268
2273
2274
2280
2282
...

result:

ok q=100000

Test #14:

score: 0
Accepted
time: 360ms
memory: 190580kb

input:

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

output:

5
450
894
1337
1779
2221
2222
2223
2224
2226
2228
2230
2231
2233
2234
2236
2237
2239
2240
2241
2243
2244
2248
2249
2250
2252
2258
2261
2265
2266
2268
2269
2270
2271
2272
2274
2275
2276
2279
2280
2283
2284
2287
2288
2289
2290
2292
2293
2294
2298
2299
2304
2305
2238
2306
2308
2311
2312
2314
2316
2319
...

result:

ok q=100000

Test #15:

score: 0
Accepted
time: 767ms
memory: 194332kb

input:

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

output:

2
447
898
894
908
913
915
918
919
921
922
926
929
930
934
936
938
939
940
942
943
944
945
946
952
953
956
958
959
960
962
963
965
966
967
968
972
975
976
977
978
980
981
985
988
990
996
997
998
1000
1001
1003
1005
924
1007
1009
1010
1012
1013
1014
916
1015
1016
1017
1018
910
1019
1020
1022
1026
1028...

result:

ok q=100000

Test #16:

score: 0
Accepted
time: 1409ms
memory: 193424kb

input:

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

output:

1
3
6
7
11
12
15
16
19
20
23
24
26
27
29
30
31
32
33
34
36
38
39
41
42
43
45
46
47
49
51
53
57
60
61
62
63
68
69
13
70
76
78
80
81
82
83
84
87
88
89
94
99
101
103
104
109
114
115
116
119
120
124
126
127
128
130
131
134
136
138
139
140
141
143
144
145
148
151
152
153
154
155
156
157
158
160
161
164
1...

result:

ok q=100000

Test #17:

score: 0
Accepted
time: 2321ms
memory: 190448kb

input:

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

output:

1
2
3
5
6
7
8
9
10
11
14
16
19
20
22
23
24
26
28
34
36
37
38
39
41
42
48
50
52
56
57
58
61
64
65
66
69
72
73
74
75
77
80
84
85
86
88
91
93
96
98
100
101
103
104
112
113
114
116
117
120
122
124
130
133
136
138
141
142
143
145
146
148
149
154
155
160
162
165
167
170
171
172
174
176
177
180
182
184
189...

result:

ok q=100000

Test #18:

score: -100
Time Limit Exceeded

input:

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

output:

6
7
8
9
10
11
13
14
16
17
19
21
22
23
24
25
28
30
31
36
37
38
39
40
41
43
45
49
52
53
55
57
60
61
66
67
68
69
70
71
72
74
75
77
78
79
81
82
83
84
88
90
91
96
98
100
104
105
107
108
110
111
112
115
116
118
119
120
121
123
127
130
131
135
140
143
144
150
151
156
159
161
163
165
168
169
171
173
179
180...

result: