結果

問題 No.2604 Initial Motion
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2024-01-12 23:00:33
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,938 ms / 3,000 ms
コード長 1,960 bytes
コンパイル時間 5,618 ms
コンパイル使用メモリ 281,960 KB
実行使用メモリ 71,856 KB
最終ジャッジ日時 2024-01-12 23:00:57
合計ジャッジ時間 22,577 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 15 ms
6,676 KB
testcase_04 AC 16 ms
6,676 KB
testcase_05 AC 14 ms
6,676 KB
testcase_06 AC 15 ms
6,676 KB
testcase_07 AC 16 ms
6,676 KB
testcase_08 AC 16 ms
6,676 KB
testcase_09 AC 15 ms
6,676 KB
testcase_10 AC 15 ms
6,676 KB
testcase_11 AC 16 ms
6,676 KB
testcase_12 AC 13 ms
6,676 KB
testcase_13 AC 1,022 ms
47,888 KB
testcase_14 AC 424 ms
25,844 KB
testcase_15 AC 306 ms
21,084 KB
testcase_16 AC 761 ms
38,328 KB
testcase_17 AC 1,938 ms
71,856 KB
testcase_18 AC 1,569 ms
63,412 KB
testcase_19 AC 1,366 ms
57,664 KB
testcase_20 AC 739 ms
36,324 KB
testcase_21 AC 446 ms
26,600 KB
testcase_22 AC 1,387 ms
60,604 KB
testcase_23 AC 555 ms
29,908 KB
testcase_24 AC 902 ms
45,992 KB
testcase_25 AC 907 ms
71,200 KB
testcase_26 AC 648 ms
33,432 KB
testcase_27 AC 305 ms
19,612 KB
testcase_28 AC 557 ms
30,388 KB
testcase_29 AC 1,022 ms
48,628 KB
testcase_30 AC 340 ms
21,332 KB
testcase_31 AC 670 ms
34,568 KB
testcase_32 AC 358 ms
36,504 KB
testcase_33 AC 4 ms
6,676 KB
testcase_34 AC 3 ms
6,676 KB
testcase_35 AC 61 ms
6,676 KB
testcase_36 AC 294 ms
6,676 KB
testcase_37 AC 3 ms
6,676 KB
testcase_38 AC 4 ms
6,676 KB
testcase_39 AC 3 ms
6,676 KB
testcase_40 AC 148 ms
6,676 KB
testcase_41 AC 193 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/mincostflow>
using namespace atcoder;

const long long INF = 1e18;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
    int n,k,m;
    cin >> k >> n >> m;

    vector<int> A(k);
    vector<int> B(n);

    for (auto &a: A) cin >> a;
    for (auto &b: B) cin >> b;

    vector<vector<pair<int, long long>>> e(n);
    for (int i = 0; i < m ; i++){
        int u,v;
        long long d;
        cin >> u >> v >> d;
        u--;v--;
        e[u].emplace_back(v,d);
        e[v].emplace_back(u,d);
    }

    int s = n+n, t = s+1;
    mcf_graph<int, long long> g(t+1);

    vector<int> count(n);
    for (int i = 0; i < k; i++){
        count[A[i]-1]++;
    }
    for (int i = 0; i < n; i++){
        if (B[i]){
            int mi = min(B[i],count[i]);
            B[i] -= mi;
            count[i] -= mi;
        }
    }

    for (int i = 0; i < n; i++){

        if (count[i]==0) continue;
        
        vector<long long> dist(n,INF);
        dist[i] = 0;

        priority_queue<pair<long long, int>,vector<pair<long long, int>>,greater<pair<long long ,int>>> h;
        h.push(pair(0,i));

        while (!h.empty())
        {
            auto [d,now] = h.top(); h.pop();
            if (dist[now] != d) continue;

            for (auto [nex,nd]: e[now]){
                if (dist[nex] > d+nd){
                    dist[nex] = d+nd;
                    h.push(pair(d+nd,nex));
                }
            }
        }

        for (int j = 0; j < n; j++){
            if (B[j] == 0) continue;

            g.add_edge(i,n+j,count[i],dist[j]);
        }
   
    }
    int flow = 0;
    for (int i = 0; i < n; i++){
        if (B[i]){
            g.add_edge(n+i,t,B[i],0);
        }
        if (count[i]){
            g.add_edge(s,i,count[i],0);
            flow += count[i];
        }
    }

    auto result = g.flow(s,t,flow);
    cout << result.second << endl;

    return 0;

}
0