QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#282281#1359. Setting Maps_LAP_WA 28ms159784kbC++143.3kb2023-12-11 17:49:232023-12-11 17:49:23

Judging History

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

  • [2023-12-11 17:49:23]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:159784kb
  • [2023-12-11 17:49:23]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 210, M = 510;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
int n, m, k, s, t, c[N];

struct Dinic {
    static const int N = 5e6 + 10;
    struct edge {
        int from, to;
        long long cap, flow;
        edge(int u, int v, long long c, long long f): from(u), to(v), cap(c), flow(f) {}
    };
    vector<edge> edges; vector<int> G[N];
    inline void AddEdge(int u, int v, long long c) {
        static int M;
        edges.emplace_back(edge(u, v, c, 0)), edges.emplace_back(edge(v, u, 0, 0));
        M = edges.size(); G[u].emplace_back(M - 2), G[v].emplace_back(M - 1);
    }
    int d[N], cur[N], s, t;
    inline bool BFS() {
        memset(d, 0, sizeof d); d[s] = 1;
        queue<int> Q; Q.push(s);
        while(!Q.empty()) {
            int u = Q.front(); Q.pop();
            for(auto i : G[u]) {
                if(d[edges[i].to] || edges[i].flow == edges[i].cap) continue;
                d[edges[i].to] = d[u] + 1, Q.push(edges[i].to);
            }
        }
        return d[t];
    }
    long long dfs(int u, long long F) {
        if(u == t || F <= 0) return F;
        long long flow = 0;
        for(int &i = cur[u]; i < G[u].size(); i ++) {
            auto &e = edges[G[u][i]];
            if(d[e.to] != d[e.from] + 1 || e.flow == e.cap) continue;
            long long f = dfs(e.to, min(e.cap - e.flow, F));
            flow += f, F -= f, e.flow += f, edges[G[u][i] ^ 1].flow -= f;
            if(!F) break;
        }
        return flow;
    }
    inline long long MaxFlow(int s, int t) {
        long long res = 0; this->s = s, this->t = t;
        while(BFS()) {
            memset(cur, 0, sizeof cur);
            res += dfs(s, INF);
        }
        return res;
    }
    bool vis[N];
    void print_dfs(int u) {
        vis[u] = true;
        for(auto i : G[u]) {
            auto &e = edges[i];
            if(vis[e.to] || e.cap == e.flow) continue;
            print_dfs(e.to);
        }
    }
    inline void print() {
        print_dfs(s);
        vector<int> res;
        for(auto &e : edges) {
            if((int)vis[e.from] + (int)vis[e.to] == 1) res.emplace_back(e.from / k / 2 + 1);
        }
        sort(res.begin(), res.end()), res.erase(unique(res.begin(), res.end()), res.end());
        cout << res.size() << '\n';
        for(auto x : res) cout << x << ' ';
        cout << '\n';
    }
} solver;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);

    cin >> n >> m >> k >> s >> t; s --, t --;
    for(int i = 0; i < n; i ++) cin >> c[i];
    for(int i = 0; i < n; i ++) {
        for(int j = 0; j < k; j ++)
            solver.AddEdge((i * 2) * k + j, (i * 2 + 1) * k + j, c[i]);
    }
    for(int i = 0; i < n; i ++) {
        for(int j = 1; j < k; j ++)
            solver.AddEdge((i * 2) * k + j - 1, (i * 2 + 1) * k + j, INF);
    }

    for(int i = 1; i <= m; i ++) {
        int a, b; cin >> a >> b; a --, b --;
        for(int j = 0; j < k; j ++)
            solver.AddEdge((a * 2 + 1) * k + j, (b * 2) * k + j, INF);
    }
    int T = ((n - 1) * 2 + 1) * k + k;
    for(int j = 0; j < k; j ++) solver.AddEdge((t * 2 + 1) * k + j, T, INF);

    long long ans = solver.MaxFlow((s * 2) * k + 0, T);
    if(ans < INF) solver.print();
    else cout << "-1" << '\n';

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 23ms
memory: 159700kb

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: 28ms
memory: 159756kb

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: 20ms
memory: 159784kb

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:

7
1 5 6 7 8 9 10 

result:

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