QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#251881#6766. Direction Settinghaze#AC ✓2ms4192kbC++203.7kb2023-11-15 11:48:482023-11-15 11:48:48

Judging History

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

  • [2023-11-15 11:48:48]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:4192kb
  • [2023-11-15 11:48:48]
  • 提交

answer

/*
Author: haze
2023/11/15
11:19
*/

#include <bits/stdc++.h>

#define irep(i, l, r) for(int (i) = (l); (i) <= (r); ++(i))
#define drep(i, r, l) for(int (i) = (r); (i) >= (l); --(i))
#define ll long long
#define LL __int128
using namespace std;

inline ll read() {
    char ch = getchar();
    ll s = 0;
    bool w = 0;
    while (!isdigit(ch)) {
        if (ch == '-')w = 1;
        ch = getchar();
    }
    while (isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
    return w ? -s : s;
}

inline char rc() {
    char ch = getchar();
    while (1) {
        if (ch >= '!' && ch <= '~')return ch;
        ch = getchar();
    }
}

template<class T1, class T2>
T1 min(T1 AA, T2 BB) { return AA > BB ? BB : AA; }

template<class T1, class T2>
T1 max(T1 AA, T2 BB) { return AA < BB ? BB : AA; }

const int itinf = 1e9;
const ll llinf = 4e18;
const int mod = 1000000007;
const int N = 500009;

struct augment_path {
    vector<vector<int> > g;
    vector<int> pa;  // 匹配
    vector<int> pb;
    vector<int> vis;  // 访问
    int n, m;         // 两个点集中的顶点数量
    int dfn;          // 时间戳记
    int res;          // 匹配数

    augment_path(int _n, int _m) : n(_n), m(_m) {
        assert(0 <= n && 0 <= m);
        pa = vector<int>(n, -1);
        pb = vector<int>(m, -1);
        vis = vector<int>(n);
        g.resize(n);
        res = 0;
        dfn = 0;
    }

    void add(int from, int to) {
        assert(0 <= from && from < n && 0 <= to && to < m);
        g[from].push_back(to);
    }

    bool dfs(int v) {
        vis[v] = dfn;
        for (int u : g[v]) {
            if (pb[u] == -1) {
                pb[u] = v;
                pa[v] = u;
                return true;
            }
        }
        for (int u : g[v]) {
            if (vis[pb[u]] != dfn && dfs(pb[u])) {
                pa[v] = u;
                pb[u] = v;
                return true;
            }
        }
        return false;
    }

    int solve() {
        while (true) {
            dfn++;
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if (pa[i] == -1 && dfs(i)) {
                    cnt++;
                }
            }
            if (cnt == 0) {
                break;
            }
            res += cnt;
        }
        return res;
    }
};

void solve(){
    int n = read(), m = read(), sumdeg = 0;
    vector<int>lim(n), deg(n);
    vector<array<int, 2>>edge(m), rg(n);
    irep(i, 0, n - 1)lim[i] = read();
    irep(i, 0, m - 1){
        int u = read() - 1, v = read() - 1;
        edge[i] = {u, v};
        deg[u] ++, deg[v] ++;
    }
    irep(i, 0, n - 1)lim[i] = min(lim[i], deg[i]), sumdeg += lim[i];
    int st = 0;
    vector<int>id(sumdeg);
    irep(i, 0, n - 1){
        rg[i] = {st, st + lim[i] - 1};

        irep(j, st, st + lim[i] - 1)id[j] = i;

        st += lim[i];
    }
    //for(auto [l, r] : rg)cerr << l << ' ' << r << endl;
    augment_path G(sumdeg, m);
    irep(k, 0, m - 1){
        auto [u, v] = edge[k];
        auto [li, ri] = rg[u];
        auto [lj, rj] = rg[v];
        irep(i, li, ri){
            G.add(i, k);
        }
        irep(j, lj, rj){
            G.add(j, k);
        }
    }

    int ans = G.solve();
    printf("%d\n",m - ans);
    irep(i, 0, m - 1){
        int mt = G.pb[i];
        auto [u, v] = edge[i];
        if(mt == -1 || u == id[mt])putchar('1');
        else putchar('0');
    }
    putchar('\n');
}

int main() {
    int T = read();
    while(T --){
        solve();
    }
    return 0;
}
/*
 2
 4 5
 0 1 1 5
 1 2
 1 3
 2 3
 3 2
 4 4
 3 2
 0 0 2
 1 3
 3 2
 */

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

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

input:

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

output:

2
00111
0
01

result:

ok 2 cases

Test #2:

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

input:

120
21 14
0 1 2 2 3 2 0 1 0 3 3 2 1 1 2 0 1 3 1 0 0
6 12
14 11
10 18
15 12
6 11
15 8
3 4
10 11
3 18
5 13
5 19
5 10
17 18
4 2
20 21
9 3 0 4 7 9 5 2 0 4 0 1 6 1 5 8 3 2 7 0
16 6
12 6
11 4
6 6
19 10
17 19
20 20
1 17
15 10
3 2
5 16
7 8
6 1
6 4
18 16
1 8
4 1
20 6
6 9
4 15
7 5
6 16
12 8 0 9 5 8
4 5
6 3
2 ...

output:

0
10101011111110
1
000101110011000100110
0
1111101100011001
2
111100111000101011001101
2
01101000011
2
000100011011110011010011
3
0100101111010111010011
0
11
0
1101110010010011110
0
0110001100100110
2
0110110001000
3
101101001
0
0010011
0
000010001110010
0
1111101111101011001
2
10110111100000001111
...

result:

ok 120 cases

Test #3:

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

input:

120
5 9
1 2 2 3 1
2 2
2 4
1 5
4 3
3 4
3 3
1 5
5 4
4 3
5 4
1 0 1 1 1
2 3
5 3
1 4
4 3
15 17
0 1 1 3 1 2 1 1 1 1 1 2 0 1 1
14 6
13 12
11 4
9 8
9 4
10 5
10 2
4 4
7 4
11 10
15 6
7 1
5 3
13 14
15 12
2 14
11 6
13 17
2 2 1 1 2 1 0 0 1 4 1 1 1
5 11
6 2
2 1
5 2
1 12
7 10
10 2
1 3
3 11
7 1
9 7
11 10
11 2
4 3
7...

output:

0
111111001
0
0111
0
00001011011100010
0
11110011101101001
0
0101111
5
1000111100111
4
1111011
2
001011101110011111111
0
01110
0
0110
0
11100
0
1001
5
11110100110101011
4
111111111
4
01111111
4
10101010111110100
0
110000001010100
0
010000101100001
0
0001001111010100000
4
10111000101
2
11101101001111...

result:

ok 120 cases

Test #4:

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

input:

120
12 11
7 0 0 1 0 0 1 1 0 0 1 0
12 1
1 9
1 2
1 8
3 1
6 1
10 1
1 7
5 1
11 1
4 1
11 10
1 0 0 0 1 0 7 0 0 0 1
7 11
6 7
7 5
8 7
10 7
9 7
7 4
7 1
7 2
3 7
24 23
1 1 1 1 0 5 1 1 1 1 0 1 1 1 1 0 1 0 1 1 1 1 0 1
20 6
12 6
6 9
1 6
6 15
14 6
6 2
6 18
23 6
10 6
3 6
6 16
6 7
17 6
6 13
19 6
6 22
5 6
4 6
6 11
6 ...

output:

0
01100000011
0
0000001010
0
11010101011101010011001
0
1010
0
0001101111101
0
1000110001101101011
0
10100101
0
00011011110
0
101001111011011001110110
0
1001111110010001
0
00100
0
0010101001
0
00101101011111101
0
100001110100100000
0
10011100001110011000
0
010010000101000111001
0
010
0
001100110
0
10...

result:

ok 120 cases

Test #5:

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

input:

10
300 300
0 0 0 1 6 3 0 36 0 0 0 0 8 53 23 2 8 7 8 4 1 0 3 5 0 4 0 0 2 5 5 5 7 0 0 4 3 0 0 21 2 7 6 2 0 0 0 4 0 67 3 4 9 3 1 1 0 6 2 2 0 0 0 0 0 41 5 0 0 15 2 5 0 6 5 4 0 7 4 4 6 8 0 7 2 6 0 4 4 0 8 22 1 2 6 3 0 3 6 0 0 3 0 0 6 3 0 63 3 7 7 4 0 0 0 26 0 0 1 3 6 1 1 0 0 22 0 2 0 0 1 7 4 1 0 1 0 4 0 ...

output:

31
011110111100011101110111111100000110101110010101111011001011110111101101101010111100110011111101000100101001011110101011011010111110001110010111111111101110011100111111110010000001101010011100111110000100001110111011101111100101101101101000111000011110101000100001000110100101110011101001001101111...

result:

ok 10 cases

Test #6:

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

input:

10
30 300
17 12 25 27 17 21 21 24 10 18 23 19 25 26 14 23 9 27 22 19 25 15 13 22 25 12 20 10 27 22
29 11
25 9
23 10
9 25
25 12
20 1
18 9
2 1
30 14
2 10
6 18
3 27
10 17
14 4
21 2
2 15
28 4
7 8
19 13
14 13
8 7
10 18
4 18
4 19
5 16
23 14
21 24
24 12
15 24
23 29
11 25
10 4
23 9
27 13
18 26
12 24
23 3
27...

output:

0
0001000001111001010001111010111000110000100111110100110111001110001111111110001011111000010000110111001010010110101010100001101110011011101011011010100000100100111101001000100010110101111001000000011000000011000000110111111100011001000000111011111111010011011110001011001000100001111011001001001000...

result:

ok 10 cases

Test #7:

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

input:

10
290 299
0 3 2 1 2 0 0 0 0 1 0 3 2 1 3 0 0 3 1 0 3 1 0 1 0 0 0 1 0 3 0 1 0 2 1 7 0 1 0 3 0 2 1 2 1 2 0 1 0 0 2 2 1 0 0 0 0 1 2 0 2 1 0 1 2 1 1 0 1 0 0 0 1 1 1 1 1 2 2 1 3 0 0 1 2 0 1 0 1 2 1 1 0 0 2 1 2 1 1 0 1 0 2 0 0 1 1 0 0 1 0 4 1 2 2 1 1 1 1 2 2 3 1 1 1 0 1 2 1 1 2 0 1 1 1 1 0 0 2 1 1 0 0 1 1...

output:

0
1111100000010110001101010001000010011010011010010100011001001000000010011100100011101100001001101110000111111110010001110000011000000111011001011110101010101110110100001110001000111100000010111010011001100101011100000110001100011001001101000001111100011000001010001001100100011101001000000111010101...

result:

ok 10 cases

Test #8:

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

input:

10
300 299
1 1 1 1 1 1 0 1 0 0 1 1 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 1 1 0 1 1 0 1 1 1 1 1 1 0 1 1 1 0 0 1 142 1 0 0 1 1 1 0 0 0 1 0 1 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 0 0 1 0 0 1 0 1 1 0 1 1 1 1 0...

output:

0
0111101010001110110101100110100101010010001000100000011000100101111101111101010111000110110010110011010000011011011101000000111011111001010111001011010110010000110010110000010111011100111100100011110110010010101111110011110011001001101011010100101001110111101100000101101111110010001110011010111011...

result:

ok 10 cases