結果

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
const long long INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int n; cin >> n;
	vector<int>p(n);
	rep(i, n)cin >> p[i];
	int m; cin >> m;
	vector<int>u(m), v(m);
	rep(i, m) {
		cin >> u[i] >> v[i];
		u[i]--, v[i]--;
	}
	int k; cin >> k;
	vector<int>a(k), b(k), s(k);
	rep(i, k) {
		cin >> a[i] >> b[i] >> s[i];
		a[i]--, b[i]--;
	}
	int st = n + k;
	int ed = st + 1;
	mf_graph<long long>g(ed + 1);
	long long ans = 0;
	rep(i, n) {
		if (p[i] >= 0) {
			g.add_edge(st, i, p[i]);
			ans += p[i];
		}
		else {
			g.add_edge(i, ed, -p[i]);
		}
	}
	rep(i, m) {
		g.add_edge(v[i], u[i], INF * 4);
	}
	rep(i, k) {
		int x = n + i;
		g.add_edge(x, a[i], INF * 4);
		g.add_edge(x, b[i], INF * 4);
		g.add_edge(st, x, s[i]);
		ans += s[i];
	}
	auto tmp = g.flow(st, ed);
	ans -= tmp;
	cout << ans << endl;
	return 0;
}
0