QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#812071#1359. Setting MapsRong7WA 0ms3960kbC++144.4kb2024-12-13 11:15:502024-12-13 11:16:00

Judging History

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

  • [2024-12-13 11:16:00]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3960kb
  • [2024-12-13 11:15:50]
  • 提交

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] || (e & 1)) 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;
}

詳細信息

Test #1:

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

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: 3768kb

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: -100
Wrong Answer
time: 0ms
memory: 3960kb

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:

8
3 4 5 6 7 8 9 10

result:

wrong answer User answer is not optimal; judge: 60, user: 80