結果

問題 No.3201 Corporate Synergy
ユーザー 沙耶花
提出日時 2025-07-11 22:05:27
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 5,863 ms
コンパイル使用メモリ 255,876 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-07-11 22:05:35
合計ジャッジ時間 5,881 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000005
#define Inf64 1000000000000000001LL

int main(){
	
	int n;
	cin>>n;
	
	mf_graph<long long> G(n+2);
	int S = n,T = n+1;
	long long ans = 0;
	rep(i,n){
		long long p;
		cin>>p;
		if(p>=0){
			ans += p;
			G.add_edge(S,i,p);
			G.add_edge(i,T,0);
		}
		else{
			G.add_edge(i,T,-p);
			G.add_edge(S,i,0);
		}

	}
	int m;
	cin>>m;
	rep(i,m){
		int u,v;
		cin>>u>>v;
		u--,v--;
		G.add_edge(v,u,Inf64);
	}
	
	int k;
	cin>>k;
	rep(_,k){
		int a,b,c;
		cin>>a>>b>>c;
		ans += c;
		a--,b--;
		G.add_edge(S,a,c);
		G.add_edge(a,b,c);
	}
	ans -= G.flow(S,T);
	cout<<ans<<endl;
	return 0;
}
0