結果
| 問題 |
No.3201 Corporate Synergy
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-12 11:13:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 2,000 ms |
| コード長 | 1,909 bytes |
| コンパイル時間 | 2,308 ms |
| コンパイル使用メモリ | 199,088 KB |
| 実行使用メモリ | 11,776 KB |
| 最終ジャッジ日時 | 2025-07-12 11:13:14 |
| 合計ジャッジ時間 | 2,969 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:70:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
70 | scanf("%d", v + i);
| ~~~~~^~~~~~~~~~~~~
main.cpp:78:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
78 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:84:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
84 | scanf("%d%d%d", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000086, MOD = 998244353, INF = 0x3f3f3f3f;
ll res;
int n, m, cnt;
ll w[N];
int e[N], ne[N], h[N], idx, v[N], S, T;
int d[N], cur[N];
void add(int a, int b, ll c) {
e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++;
e[idx] = a, ne[idx] = h[b], w[idx] = 0, h[b] = idx++;
}
inline bool bfs() {
queue<int> q;
memset(d, -1, sizeof(int) * (cnt + 10));
memcpy(cur, h, sizeof(int) * (cnt + 10));
d[S] = 0;
q.push(S);
while (q.size()) {
auto u = q.front();
q.pop();
for (int i = h[u]; ~i; i = ne[i]) {
int j = e[i];
if (w[i] && d[j] == -1) {
d[j] = d[u] + 1;
if (j == T) return true;
q.push(j);
}
}
}
return false;
}
inline ll dfs(int r, int limit) {
if (r == T) return limit;
ll res = 0;
for (int i = cur[r]; ~i && res < limit; i = ne[i]) {
cur[r] = i;
int j = e[i];
if (d[j] == d[r] + 1 && w[i]) {
ll t = dfs(j, min(limit - res, (ll)w[i]));
if (!t) d[j] = -1;
w[i] -= t, w[i ^ 1] += t, res += t;
}
}
return res;
}
inline ll dinic() {
ll res = 0, t;
while (bfs()) while (t = dfs(S, INF)) res += t;
return res;
}
int main() {
memset(h, -1, sizeof h);
cin >> n;
ll sum = 0;
S = 0, T = n + 1;
for (int i = 1; i < n + 1; i++) {
scanf("%d", v + i);
if (v[i] < 0) add(i, T, -v[i]);
else add(0, i, v[i]), sum += v[i];
}
cnt = n + 1;
cin >> m;
for (int i = 1; i < m + 1; i++) {
int a, b;
scanf("%d%d", &a, &b);
add(b, a, 1e18);
}
cin >> m;
while (m--) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
sum += c;
++cnt;
add(0, cnt, c);
add(cnt, a, 1e18);
add(cnt, b, 1e18);
}
printf("%lld\n", sum - dinic());
return 0;
}