QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#812075#1359. Setting MapsRong7WA 1ms4108kbC++144.4kb2024-12-13 11:18:132024-12-13 11:18:14

Judging History

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

  • [2024-12-13 11:18:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4108kb
  • [2024-12-13 11:18:13]
  • 提交

answer

// Go in my style.
// Not afraid to dark.

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

clock_t sttime;
#define STCLOCK sttime = clock ();
#define TIMENOW fprintf (stderr, "\nNOW TIME COSSEMED: %0.4lf\n", 1.0 * (clock () - sttime) / CLOCKS_PER_SEC);
#define inline __inline__ __attribute__ ((always_inline))

namespace io {
    int read_pos, read_dt; char read_char;
    inline int read (int &p = read_pos){
        p = 0, read_dt = 1; read_char = getchar ();
        while (! isdigit (read_char)){
            if (read_char == '-')
                read_dt = - 1;
            read_char = getchar ();
        }
        while (isdigit (read_char)){
            p = (p << 1) + (p << 3) + read_char - 48;
            read_char = getchar ();
        }
        return p = p * read_dt;
    }
    int write_sta[65], write_top;
    inline void write (int x){
        if (x < 0)
            putchar ('-'), x = - x;
        write_top = 0;
        do
            write_sta[write_top ++] = x % 10, x /= 10;
        while (x);
        while (write_top)
            putchar (write_sta[-- write_top] + 48);
    }
}

const int N = 2e2, M = 5e2, T = 5, inf = 0x3f3f3f3f;
int n, m, t, S, E, c[N + 5];

inline int vx (int i, int x, int o){
    return i + (x - 1) * n + o * n * t;
}
const int PS = N * T * 4 + 5, ES = N * T * 20 + 5;
struct Maxflow {
    int s, t, lrg;
    int firs[PS], nex[ES], to[ES], w[ES], tot;
    int cur[PS], dep[PS];
    bool inq[PS];
    bool inS[PS];
    inline void Add (int u, int v, int l){
        nex[++ tot] = firs[u], firs[u] = tot, to[tot] = v, w[tot] = l;
        nex[++ tot] = firs[v], firs[v] = tot, to[tot] = u, w[tot] = 0;
    }
    inline void init (){ tot = 1; for (int i = 1;i <= lrg;++ i) firs[i] = 0, inS[i] = false; }
    inline bool Bfs (){
        for (int i = 1;i <= lrg;++ i) cur[i] = firs[i], dep[i] = inf, inq[i] = false;
        queue < int > Q;
        Q.push (s); dep[s] = 0; inq[s] = true;
        while (! Q.empty ()){
            int u = Q.front (); Q.pop (); inq[u] = false;
            for (int e = firs[u], v;e;e = nex[e]){
                v = to[e];
                if (w[e] && dep[v] > dep[u] + 1){
                    dep[v] = dep[u] + 1;
                    if (! inq[v]){
                        inq[v] = true;
                        Q.push (v);
                    }
                }
            }
        }
        return dep[t] != inf;
    }
    int Dfs (int u, int flow){
        if (u == t) return flow;
        int used = 0, rlow;
        for (int &e = cur[u], v;e;e = nex[e]){
            v = to[e];
            if (w[e] && dep[v] == dep[u] + 1){
                rlow = Dfs (v, min (flow - used, w[e]));
                if (rlow){
                    w[e] -= rlow; w[e ^ 1] += rlow; used += rlow;
                    if (used == flow) break;
                }
            }
        }
        return used;
    }
    inline int FLOW (){
        static int Ansflow; Ansflow = 0;
        while (Bfs () && Ansflow < inf) Ansflow += Dfs (s, inf);
        return min (Ansflow, inf);
    }
    void GET (int u){
        inS[u] = true;
        for (int e = firs[u], v;e;e = nex[e]){
            v = to[e];
            if (inS[v] || ! w[e]) continue;
            GET (v);
        }
    }
} G;

int ans[N + 5], cnt;

signed main (){
    STCLOCK

    io::read (n), io::read (m), io::read (t), io::read (S), io::read (E);
    G.s = vx (S, t, 0), G.t = vx (E, 1, 1), G.lrg = vx (n, t, 1);
    G.init ();
    for (int i = 1;i < t;++ i) G.Add (vx (E, i + 1, 1), vx (E, i, 1), inf);
    for (int i = 1;i <= n;++ i){
        io::read (c[i]);
        for (int j = 1;j <= t;++ j) G.Add (vx (i, j, 0), vx (i, j, 1), c[i]);
        for (int j = 1;j < t;++ j) G.Add (vx (i, j + 1, 0), vx (i, j, 1), inf);
    }
    for (int i = 1, u, v;i <= m;++ i){
        io::read (u), io::read (v);
        for (int j = 1;j <= t;++ j) G.Add (vx (u, j, 1), vx (v, j, 0), inf);
    }
    int R = G.FLOW ();
    if (R == inf) puts ("-1");
    else {
        G.GET (G.s);
        for (int i = 1;i <= n;++ i) 
            for (int j = 1;j <= t;++ j)
                if (G.inS[vx (i, j, 0)] && ! G.inS[vx (i, j, 1)]){
                    ans[++ cnt] = i;
                    break;
                }
        io::write (cnt), putchar ('\n');
        for (int i = 1;i <= cnt;++ i) io::write (ans[i]), putchar (i == cnt ? '\n' : ' ');
    }

    TIMENOW
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2 5
1 3
1 60 35
1 2
2 3

output:

-1

result:

ok answer = IMPOSSIBLE

Test #2:

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

input:

7 11 1
1 7
100 5 7 16 11 12 100
1 2
1 3
1 4
1 5
2 3
2 6
3 6
4 3
4 7
5 7
6 7

output:

4
2 3 4 5

result:

ok answer = 39

Test #3:

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

input:

11 17 2
1 11
1000 10 10 10 10 10 10 10 10 10 1000
1 2
1 3
1 4
1 5
1 6
2 7
3 7
4 7
5 8
6 8
7 8
7 9
7 10
8 9
8 11
9 11
10 11

output:

6
5 6 7 8 9 10

result:

ok answer = 60

Test #4:

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

input:

2 2 2
2 1
100 200
1 2
2 1

output:

2
1 2

result:

ok answer = 300

Test #5:

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

input:

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

output:

-1

result:

ok answer = IMPOSSIBLE

Test #6:

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

input:

100 120 5
1 5
5367720 2854323 1799056 9744604 3215334 7580413 6269402 3208439 8812449 3297484 2047196 4044341 7514502 2928715 9335004 3935096 6660663 3356480 4801491 5786147 895995 6710240 222342 4469390 1543213 6678041 8838445 6741919 8138951 5273670 8983795 5131484 4245746 7460466 8357966 8464419 ...

output:

-1

result:

ok answer = IMPOSSIBLE

Test #7:

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

input:

2 1 5
1 2
10 10
1 2

output:

-1

result:

ok answer = IMPOSSIBLE

Test #8:

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

input:

154 304 2
67 7
10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 100000...

output:

2
7 67

result:

ok answer = 20000000

Test #9:

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

input:

75 146 1
15 2
10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 1000000...

output:

1
15

result:

ok answer = 10000000

Test #10:

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

input:

182 360 4
97 110
10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 1000...

output:

-1

result:

ok answer = IMPOSSIBLE

Test #11:

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

input:

136 268 5
132 5
10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000...

output:

-1

result:

ok answer = IMPOSSIBLE

Test #12:

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

input:

200 396 3
174 124
10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 100...

output:

-1

result:

wrong answer User answer is not optimal; judge: 2000000000, user: 2000000010