QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#129700 | #4539. Independent Feedback Vertex Set | batrr# | AC ✓ | 864ms | 19192kb | C++17 | 1.5kb | 2023-07-22 22:19:49 | 2023-07-22 22:19:49 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 300500, inf = 1e9, mod = 998244353;
const ll INF = 1e18;
int sum(int a, int b) {
a += b;
if (a >= mod)
a -= mod;
return a;
}
int sub(int a, int b) {
a -= b;
if (a < 0)
a += mod;
return a;
}
int mult(int a, int b) {
return 1ll * a * b % mod;
}
int bp(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
int inv(int x) {
return bp(x, mod - 2);
}
int n, b[N], c[N];
ll a[N];
void solve() {
map<pii, int> mt;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
mt[{1, 2}] = 3;
mt[{1, 3}] = 2;
mt[{2, 3}] = 1;
for (int i = 4; i <= n; i++) {
cin >> b[i] >> c[i];
mt[{b[i], i}] = c[i];
mt[{c[i], i}] = b[i];
}
for (int i = n; i >= 4; i--) {
int j = mt[{min(b[i], c[i]), max(b[i], c[i])}];
a[j] += a[i];
}
cout << max({a[1], a[2], a[3]}) << "\n";
}
int main() {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << endl;
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 864ms
memory: 19192kb
input:
1000 1561 14 78 18 74 80 97 70 49 39 81 79 65 55 1 29 32 91 73 94 41 69 41 79 34 62 81 25 33 76 26 57 69 66 48 37 78 67 50 21 8 27 58 58 32 8 42 31 52 35 36 99 56 61 27 4 64 50 59 43 55 73 53 41 80 94 32 56 59 19 57 28 56 35 73 70 13 18 6 96 47 71 29 16 73 65 27 61 68 50 11 21 96 19 18 33 97 6 43 19...
output:
26477 730 133872218725 206 139 26838 225784601561 409 163907525588 65 27568981002 26830437 612 206 647 3808763 392 39765006630 9823066 71309193 126 10667 93591615 12028 113 12356789 2420359 213 418 223 166 40 5324 219 1419 562 663 22941 14 39 102638547 14199134 58 201 12653791 101 10447 16511 171245...
result:
ok 1000 lines