結果
問題 |
No.3201 Corporate Synergy
|
ユーザー |
![]() |
提出日時 | 2025-07-11 22:01:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,443 bytes |
コンパイル時間 | 5,134 ms |
コンパイル使用メモリ | 306,412 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-07-11 22:01:08 |
合計ジャッジ時間 | 5,241 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VL p(n); rep(i, n) cin >> p[i], p[i] *= 2; constexpr long long INF = 1002003004005006007; int s = n, t = n + 1; mf_graph<ll> g(t + 1); int m; cin >> m; rep(_, m) { int u, v; cin >> u >> v; g.add_edge(v - 1, u - 1, INF); } int k; cin >> k; rep(_, k) { int a, b, s; cin >> a >> b >> s; a--, b--; p[a] += s; p[b] += s; g.add_edge(a, b, s); g.add_edge(b, a, s); } ll ans = 0; rep(i, n) { if (p[i] > 0) { ans += p[i]; g.add_edge(s, i, p[i]); } else { g.add_edge(i, t, -p[i]); } } ans -= g.flow(s, t); cout << ans / 2 << '\n'; }