結果

問題 No.3201 Corporate Synergy
ユーザー otoshigo
提出日時 2025-07-11 23:04:47
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,394 bytes
コンパイル時間 3,401 ms
コンパイル使用メモリ 287,116 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-07-11 23:04:52
合計ジャッジ時間 4,432 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define rrep(i, s, t) for(ll i = (ll)(t) - 1; i >= (ll)(s); i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define TT template<typename T>
TT using vec = vector<T>;
template<class T1, class T2> bool chmin(T1 &x, T2 y) { return x > y ? (x = y, true) : false; }
template<class T1, class T2> bool chmax(T1 &x, T2 y) { return x < y ? (x = y, true) : false; }

struct io_setup {
    io_setup() {
        ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        cout << fixed << setprecision(15);
    }
} io_setup;

#include<atcoder/maxflow>
const ll INF=1LL<<60;

void solve(){
    ll N;
    cin>>N;
    atcoder::mf_graph<ll>G(500);
    ll S=0,T=N+1;
    ll cost=0;
    rep(i,0,N){
        ll p;
        cin>>p;
        if(p<0)G.add_edge(S,i+1,-p);
        else{
            cost+=p;
            G.add_edge(i+1,T,p);
        }
    }
    ll M;
    cin>>M;
    rep(i,0,M){
        ll u,v;
        cin>>u>>v;
        G.add_edge(u,v,INF);
    }
    ll K;
    cin>>K;
    ll now=N+2;
    rep(i,0,K){
        ll a,b,s;
        cin>>a>>b>>s;
        cost+=s;
        G.add_edge(now,T,s);
        G.add_edge(a,now,INF);
        G.add_edge(b,now,INF);
        now++;
    }
    cost-=G.flow(S,T);
    cout<<cost<<"\n";
}

int main() {
    solve();
}
0