QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#55170#1344. Rooks Gameckiseki#WA 4ms3772kbC++1.8kb2022-10-12 16:48:382022-10-12 16:48:39

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-12 16:48:39]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3772kb
  • [2022-10-12 16:48:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
static constexpr int maxn = 1000 + 5;

struct Match {
    vector<int> X[maxn];
    int fX[maxn], fY[maxn], n;
    bitset<maxn> vis;
    bool dfs(int x) {
        for (auto i : X[x]) {
            if (not vis[i]) {
                vis[i] = true;
                if (fY[i] == -1 or dfs(fY[i])) {
                    fY[fX[x] = i] = x;
                }
                return true;
            }
        }
        return false;
    }
    void init(int n_, int m) {
        vis.reset();
        fill_n(X, n = n_, vector<int>());
        memset(fX, -1, sizeof(int) * n);
        memset(fY, -1, sizeof(int) * m);
    }
    void add_edge(int x, int y) { X[x].push_back(y); }
    int solve() {
        for (int i = 0; i < n; ++i) {
            vis.reset();
            dfs(i);
        }
        int cnt = 0;
        for (int i = 0; i < n; ++i)
            cnt += fX[i] != -1;
        return cnt;
    }
} ma;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int n, m; cin >> n >> m;
    ma.init(n, n);
    vector<vector<int>> g(n + n);
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        --a, --b;
        ma.add_edge(a, b);
        g[a].push_back(b + n);
        g[b + n].push_back(a);
    }
    auto count = [&]{
        int ans = 0;
        vector<bool> vis(n + n);
        auto dfs = [&](auto self, int i) -> void {
            vis[i] = true;
            for (int j : g[i]) {
                if (not vis[j]) self(self, j);
            }
        };
        for (int i = 0; i < n + n; ++i) {
            if (vis[i]) continue;
            if (g[i].empty()) continue;
            dfs(dfs, i);
            ans++;
        }
        return ans;
    };
    cout << m - ma.solve() << ' ' << m - count() << '\n';
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 3596kb

input:

8 3
1 1
1 8
8 8

output:

1 2

result:

ok 2 number(s): "1 2"

Test #2:

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

input:

8 4
1 1
1 8
8 8
8 1

output:

2 3

result:

ok 2 number(s): "2 3"

Test #3:

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

input:

5 5
1 1
2 2
3 3
4 4
5 5

output:

0 0

result:

ok 2 number(s): "0 0"

Test #4:

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

input:

100 1
100 100

output:

0 0

result:

ok 2 number(s): "0 0"

Test #5:

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

input:

10 12
1 2
1 4
1 6
3 6
5 6
10 7
8 7
6 7
4 7
2 7
7 3
9 5

output:

7 8

result:

ok 2 number(s): "7 8"

Test #6:

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

input:

9 12
2 3
5 8
9 7
9 9
1 2
7 8
9 1
3 3
2 9
4 4
4 6
1 6

output:

6 9

result:

ok 2 number(s): "6 9"

Test #7:

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

input:

9 1
3 3

output:

0 0

result:

ok 2 number(s): "0 0"

Test #8:

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

input:

9 13
7 6
9 6
2 3
8 7
9 7
6 4
2 7
8 8
9 8
1 8
4 6
7 4
1 4

output:

8 12

result:

ok 2 number(s): "8 12"

Test #9:

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

input:

7 13
7 3
7 2
1 1
7 5
6 5
3 3
6 1
4 6
3 2
5 7
4 3
7 4
4 7

output:

7 12

result:

ok 2 number(s): "7 12"

Test #10:

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

input:

5 18
2 5
5 4
3 4
1 5
5 3
1 2
4 3
2 4
5 1
4 5
4 2
3 5
5 5
2 3
2 1
1 1
1 3
3 1

output:

13 17

result:

ok 2 number(s): "13 17"

Test #11:

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

input:

9 5
6 9
3 2
2 8
2 9
1 1

output:

1 2

result:

ok 2 number(s): "1 2"

Test #12:

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

input:

7 18
6 7
4 1
2 4
1 2
4 5
7 6
3 1
1 6
1 4
6 5
6 6
3 3
3 2
5 2
5 7
2 7
5 4
5 1

output:

11 17

result:

ok 2 number(s): "11 17"

Test #13:

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

input:

4 6
2 4
1 2
2 1
2 3
1 1
1 3

output:

4 5

result:

ok 2 number(s): "4 5"

Test #14:

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

input:

8 17
8 3
7 8
2 2
6 3
6 2
5 2
3 2
2 3
1 8
3 8
6 8
6 5
3 4
4 4
3 7
7 1
5 4

output:

10 16

result:

ok 2 number(s): "10 16"

Test #15:

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

input:

6 15
5 2
4 1
1 3
2 5
4 2
3 6
3 2
6 5
2 3
5 6
2 4
2 1
3 1
1 4
6 4

output:

9 14

result:

ok 2 number(s): "9 14"

Test #16:

score: -100
Wrong Answer
time: 1ms
memory: 3692kb

input:

901 598
565 361
500 175
205 860
524 404
193 20
190 212
379 254
654 653
174 763
344 42
271 140
76 774
649 825
731 381
532 845
687 433
270 316
421 541
533 115
571 523
373 211
529 643
398 61
131 815
551 854
553 8
659 374
748 792
899 836
467 45
360 622
182 804
588 119
328 159
2 245
331 215
674 564
438 5...

output:

222 330

result:

wrong answer 1st numbers differ - expected: '221', found: '222'