結果
| 問題 |
No.3201 Corporate Synergy
|
| コンテスト | |
| ユーザー |
nonon
|
| 提出日時 | 2025-07-12 06:47:55 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,307 bytes |
| コンパイル時間 | 3,849 ms |
| コンパイル使用メモリ | 285,284 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-07-12 06:48:00 |
| 合計ジャッジ時間 | 4,653 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; }
bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; }
#include <atcoder/maxflow>
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
vector<int> P(N);
for (int i = 0; i < N; i++) cin >> P[i];
int M;
cin >> M;
vector<int> U(M), V(M);
for (int i = 0; i < M; i++) {
cin >> U[i] >> V[i];
U[i]--, V[i]--;
}
int K;
cin >> K;
vector<int> A(K), B(K), C(K);
for (int i = 0; i < K; i++) {
cin >> A[i] >> B[i] >> C[i];
A[i]--, B[i]--;
}
atcoder::mf_graph<long long> G(N + K + 2);
int S = N + K, T = N + K + 1;
ll ans = 0;
for (int i = 0; i < N; i++) {
if (P[i] > 0) {
ans += P[i];
G.add_edge(S, i, P[i]);
} else {
G.add_edge(i, T, -P[i]);
}
}
for (int i = 0; i < M; i++) {
G.add_edge(V[i], U[i], 1LL << 60);
}
for (int i = 0; i < K; i++) {
ans += C[i];
G.add_edge(S, i + N, C[i]);
G.add_edge(i + N, A[i], 1LL << 60);
G.add_edge(i + N, B[i], 1LL << 60);
}
ans -= G.flow(S, T);
cout << ans << endl;
}
nonon