QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#133856#6260. Historic ExhibitionKhNURE_KIVI#RE 2ms4228kbC++234.9kb2023-08-02 15:52:292023-08-02 15:52:31

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-02 15:52:31]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:4228kb
  • [2023-08-02 15:52:29]
  • 提交

answer

//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")

#ifdef __APPLE__

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>

#else
#include <bits/stdc++.h>
#endif

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

template<typename T>
bool umin(T &a, T b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool umax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#if __APPLE__
#define D for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl

template<class ...Ts>
auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }

#else
#define D while (false)
#define LOG(...)
#endif

const int max_n = -1, inf = 1000111222;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct fedge {
    int v = 0, u = 0;
    ll cap = 0, flow = 0;

    fedge(int _v, int _u, ll _cap) : v(_v), u(_u), cap(_cap) {}
};

struct Dinic {
    const ll finf = 1e18 + 42;
    vector<fedge> edg;
    vector<vector<int> > g;
    int n = 0, m = 0, s = 0, t = 0;
    vector<int> lvl, ptr;
    queue<int> q;

    Dinic(int _n, int _s, int _t) {
        n = _n;
        s = _s;
        t = _t;
        g.resize(n + 1);
        lvl.resize(n + 1);
        ptr.resize(n + 1);
    }

    void add_edge(int v, int u, ll cap) {
        edg.pb(fedge(v, u, cap));
        edg.pb(fedge(u, v, 0));
        g[v].pb(m++);
        g[u].pb(m++);
    }

    char bfs() {
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (auto &x: g[v]) {
                if (edg[x].cap - edg[x].flow < 1 || lvl[edg[x].u] != -1) continue;
                lvl[edg[x].u] = lvl[v] + 1;
                q.push(edg[x].u);
            }
        }
        return (lvl[t] != -1);
    }

    ll dfs(int v, ll pushed) {
        if (pushed <= 0) return 0;
        if (v == t) return pushed;
        for (auto &x = ptr[v]; x < g[v].size(); x++) {
            int id = g[v][x];
            int to = edg[id].u;
            if (lvl[v] + 1 != lvl[to] || edg[id].cap - edg[id].flow < 1) continue;
            ll cr = dfs(to, min(pushed, edg[id].cap - edg[id].flow));
            if (!cr) continue;
            edg[id].flow += cr;
            edg[id ^ 1].flow -= cr;
            return cr;
        }
        return 0;
    }

    ll flow() {
        ll res = 0;
        while (true) {
            for (int i = 0; i <= n; i++) {
                lvl[i] = -1;
                ptr[i] = 0;
            }
            lvl[s] = 0;
            q.push(s);
            if (!bfs()) break;
            while (true) {
                ll cr = dfs(s, finf);
                if (!cr) break;
                else res += cr;
            }
        }
        return res;
    }
};

void solve() {
    int p, v;
    cin >> p >> v;
    int sz = p + v + 10000 + 42 + 2;
    int src = sz - 2, snk = sz - 1;
    Dinic dinic(sz, src, snk);
    for(int i = 0; i < p; i++) {
        int a, b;
        cin >> a >> b;
        dinic.add_edge(src, i, 1);
        dinic.add_edge(i, p + v + a, 1);
        dinic.add_edge(i, p + v + b, 1);
    }
    vector<int> C(v);
    for(int i = 0; i < v; i++) {
        int c;
        cin >> c;
        C[i] = c;
        dinic.add_edge(p + v + c, p + i, 1);
        dinic.add_edge(p + i, snk, 1);
    }
    if(dinic.flow() != v) {
        cout << "impossible\n";
    } else {
        vector<vector<int> > av(10000 + 42);
        for(int i = 0; i < dinic.edg.size(); i += 2)
            if(dinic.edg[i].v <= p && dinic.edg[i].flow)
                av[dinic.edg[i].u - (p + v)].pb(dinic.edg[i].v + 1);
        for(int i = 0; i < v; i++) {
            cout << av[C[i]].back() << '\n';
            av[C[i]].pop_back();
        }
        cout << '\n';
    }
}

signed main() {
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;

    //cin >> t;

    while (t--) solve();

}

/*
KIVI
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1
4
3


result:

ok correct

Test #2:

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

input:

2 2
1 1
2 3
1 1

output:

impossible

result:

ok impossible

Test #3:

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

input:

2 3
9 8
4 5
4 9 5

output:

impossible

result:

ok impossible

Test #4:

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

input:

1000 1000
141 140
239 240
380 380
114 115
345 345
60 60
341 340
224 223
400 399
125 124
163 162
53 53
62 62
326 326
36 36
91 92
187 186
48 49
123 123
232 233
275 274
374 373
321 322
251 250
347 348
221 222
64 65
143 144
65 65
135 136
209 208
336 336
118 117
189 190
87 86
58 58
66 67
185 185
289 288
...

output:

854
944
757
456
727
724
955
561
607
787
288
377
876
636
533
963
642
898
792
985
715
967
421
904
662
936
591
730
781
710
875
768
909
765
762
657
728
990
326
938
918
614
961
333
494
986
289
646
941
864
426
748
445
802
903
991
493
722
753
491
729
667
832
315
859
809
422
953
910
988
588
544
676
352
536
...

result:

ok correct

Test #5:

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

input:

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

output:

72
80
95
57
43
93
65
99
91
52
47
100
59
86
96
40
29
88
55
94
77
66
33
26
79
51
85
49
63
13
97
74
89
71
92
58
75
82
42
98
73
84
56
87
76
62
37
78
60
35
90
64
68
9
69
39
83
23
38
34
17
4
53
48
30
54
46
50
41
61
14
27
12
32
31
16
21
28
25
11
10
7
81
70
5
20
67
24
3
2
19
6
8
18
36
22
15
45
1
44


result:

ok correct

Test #6:

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

input:

100 60
11 11
43 44
15 16
27 27
18 18
8 8
2 1
58 57
23 22
10 11
14 15
9 8
37 38
57 56
32 33
48 49
23 22
13 12
6 5
28 29
4 4
4 3
6 7
14 15
6 7
42 42
5 5
2 2
48 48
2 1
18 17
49 48
15 16
8 7
38 38
35 34
33 32
38 39
36 35
41 40
18 19
7 7
45 44
53 52
11 11
26 25
15 14
35 36
5 4
7 8
56 55
19 18
52 52
35 35...

output:

40
6
89
70
41
78
47
12
29
50
2
16
8
48
25
35
65
22
30
23
24
33
15
66
28
39
18
60
26
59
36
4
3
55
13
31
77
14
7
63
53
1
43
20
100
5
10
11
32
9
42
19
46
34
96
51
17
38
64
44


result:

ok correct

Test #7:

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

input:

10 7
3 4
1 1
4 4
4 5
2 3
6 6
3 2
1 2
4 3
3 4
2 1 5 4 4 3 2

output:

7
2
4
9
3
1
5


result:

ok correct

Test #8:

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

input:

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

output:

4
1
2


result:

ok correct

Test #9:

score: -100
Dangerous Syscalls

input:

10000 10000
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
10 11
...

output:


result: