QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#380597#7181. Graph Cutsucup-team992#WA 5ms3928kbC++173.5kb2024-04-07 06:20:222024-04-07 06:20:22

Judging History

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

  • [2024-04-07 06:20:22]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3928kb
  • [2024-04-07 06:20:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ar array
typedef int uci;
#define int long long
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void solve(){
    int n, m;
    cin >> n >> m;

    vector<int> deg(n);
    map<int, int> big;
    vector<int> state(n);
    vector<vector<set<ar<int, 2>>>> sides(2);
    vector<map<int, int>> adj(n);
    for(int i{}; i < m; ++i){
        int u, v;
        cin >> u >> v;
        u--, v--;

        adj[u][v] = i+1;
        adj[v][u] = i+1;
        deg[u]++, deg[v]++;
    }

    int sq = sqrt(n);
    for(int i{}; i < n; ++i){
        if(deg[i] >= sq){
            big[i] = sides[0].size();
            sides[0].push_back({});
            for(auto t : adj[i]){
                sides[0].back().insert({t.F, t.S});
            }
            sides[1].push_back({});
        }
    }

    int q;
    cin >> q;

    set<ar<int, 3>> gv;
    for(int i{}; i < q; ++i){
        char c;
        cin >> c;
        if(c == '+' || c == '-'){
            int v;
            cin >> v;
            v--;

            state[v] = 1-state[v];
            for(auto &t : big){
                if(t.F == v || !adj[v].count(t.F))
                    continue;
                sides[1-state[v]][t.S].erase({v, adj[v][t.F]});
                sides[state[v]][t.S].insert({v, adj[v][t.F]});
            }
            /*
            cout << "adding or subing " << v << '\n';
            for(auto &t : big){
                cout << t.F << '\n';

                for(int i{}; i < 2; ++i){
                    cout << "in side " << i << '\n';
                    for(auto &t : sides[i][t.S]){
                        cout << t[0] << ':' << t[1] << ' ';
                    }
                    cout << '\n';
                }
            }
            */
            if(!big.count(v)){
                for(auto [i, c] : adj[v]){
                    if(!big.count(i)){
                        if(sides[i] != sides[v]){
                            gv.insert({min(i, v), max(i, v), c});
                        }else{
                            gv.erase({min(i, v), max(i, v), c});
                        }
                    }
                }
            }
        }else{
            if(gv.size()){
                auto v = *gv.begin();
                gv.erase(gv.begin());
                cout << v[2] << '\n';
                adj[v[0]].erase(v[1]);
                adj[v[1]].erase(v[0]);
            }else{
                bool found = false;
                for(auto &t : big){
                    if(sides[1-state[t.F]][t.S].size()){
                        auto a = *sides[1-state[t.F]][t.S].begin();
                        sides[1-state[t.F]][t.S].erase(sides[1-state[t.F]][t.S].begin());
                        if(big.count(a[0])){
                            sides[1-state[a[0]]][big[a[0]]].erase({t.F, a[1]});
                        }else{
                            adj[a[0]].erase(t.F);
                        }

                        cout << a[1] << '\n';
                        found = true;
                        adj[a[0]].erase(t.F);
                        adj[t.F].erase(a[0]);
                        break;
                    }
                }
                if(!found){
                    cout << 0 << '\n';
                }
            }
        }
    }
}

uci main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3548kb

input:

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

output:

2
3
4
5
0
1
0

result:

ok q=10

Test #2:

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

input:

0 0
0

output:


result:

ok q=0

Test #3:

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

input:

0 0
1
?

output:

0

result:

ok q=1

Test #4:

score: -100
Wrong Answer
time: 5ms
memory: 3928kb

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
22
23
24
25
26
27
29
33
36
37
38
39
40
41
42
43
44
45
47
48
49
50
51
52
53
54
55
56
57
58
59
60
62
63
64
65
67
69
70
71
72
73
74
75
76
77
79
81
82
83
84
87
34
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
113
114
115
1...

result:

wrong answer Edge exists, but not found