結果

問題 No.2604 Initial Motion
ユーザー maeshunmaeshun
提出日時 2024-01-13 12:55:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,923 bytes
コンパイル時間 5,451 ms
コンパイル使用メモリ 287,420 KB
実行使用メモリ 369,104 KB
最終ジャッジ日時 2024-01-13 12:55:31
合計ジャッジ時間 11,325 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 70 ms
17,564 KB
testcase_04 AC 77 ms
17,564 KB
testcase_05 AC 70 ms
17,564 KB
testcase_06 AC 71 ms
17,564 KB
testcase_07 AC 73 ms
17,564 KB
testcase_08 AC 95 ms
17,564 KB
testcase_09 AC 68 ms
17,564 KB
testcase_10 AC 72 ms
17,564 KB
testcase_11 AC 72 ms
17,564 KB
testcase_12 AC 70 ms
17,564 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

int main()
{
    int k, n, m;
    cin >> k >> n >> m;
    vector<int> a(k), b(n);
    rep(i,k){
        cin >> a[i];
        --a[i];
    }
    rep(i,n) cin >> b[i];
    const ll INF = 1e18;
    vector<vector<P>> g(n);
    rep(i,m){
        int u, v;
        ll d;
        cin >> u >> v >> d;
        --u;--v;
        g[u].emplace_back(v,d);
        g[v].emplace_back(u,d);
    } 
    vector<int> cnt(n);
    vector<vector<ll>> mdist(n, vector<ll>(n));
    rep(i,n){
        vector<ll> dist(n, INF);
        dist[i] = 0;
        priority_queue<P, vector<P>, greater<P>> pq;
        pq.emplace(dist[i], i);
        while(!pq.empty()){
            auto [D, u] = pq.top();pq.pop();
            if(D!=dist[u]) continue;
            for(auto [v, d] : g[u]){
                if(dist[v]>dist[u] + d){
                    dist[v] = dist[u] + d;
                    pq.emplace(dist[v], v);
                }
            }
        }
        rep(j,n){
            mdist[j][i] = dist[j];
        }
    }
    vector<int> used(n);
    dbg(mdist);
    rep(i,k){
        used[a[i]]++;
    }
    mcf_graph<ll, ll> G(2*n+2);
    int s = 2*n;
    int t = 2*n+1;
    rep(i,n){
        G.add_edge(s, i, used[i], 0);
    }
    rep(i,n){
        rep(j,n){
            G.add_edge(i, j+n, used[i], mdist[i][j]);
        }
    }
    rep(i,n){
        G.add_edge(i+n, t, b[i], 0);
    }
    cout << G.flow(s,t, k).second << endl;
    dbg(G.flow(s, t,k).second);
    return 0;
}
0