QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#571842 | #9349. Exchanging Gifts | ucup-team1329 | WA | 257ms | 3804kb | C++20 | 1.4kb | 2024-09-18 09:21:45 | 2024-09-18 09:21:47 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using A2 = std::array<i64, 2>;
#define Fast_IOS std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)
const i64 mod = 998244353;
class WORK {
public:
int N;
WORK() {}
void solve() {
int n;
std::cin >> n;
std::vector<int> d(n + 1);
std::vector<i64> cnt(n + 1);
std::map<int, i64> vis;
std::vector a(n + 1, std::vector<int>());
std::vector e(n + 1, std::vector<int>());
for (int i = 1; i <= n; i++) {
int o;
std::cin >> o;
if (o == 1) {
int m;
std::cin >> m;
for (int j = 1; j <= m; j++) {
int x;
std::cin >> x;
a[i].push_back(x);
}
} else {
int x, y;
std::cin >> x >> y;
e[i].push_back(x);
e[i].push_back(y);
d[x]++;
d[y]++;
}
}
std::queue<int> q;
q.push(n);
cnt[n] = 1;
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto v : e[u]) {
d[v]--;
cnt[v] += cnt[u];
if (!d[v]) {
q.push(v);
}
}
}
i64 len = 0, max = 0;
for (int i = 1; i <= n; i++) {
len += cnt[i] * a[i].size();
for (auto x : a[i]) {
vis[x] += cnt[i];
}
}
for (auto [x, y] : vis) {
max = std::max(max, y);
}
std::cout << std::min(len, 2ll * (len - max)) << '\n';
}
};
int main() {
Fast_IOS;
WORK work;
int T = 1;
std::cin >> T;
while (T--) {
work.solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3804kb
input:
2 1 1 5 3 3 2 1 3 3 1 3 3 3 2 1 4 2 2 3 3 2 1 2
output:
4 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 257ms
memory: 3508kb
input:
10000 100 1 30 371028678 371028678 371028678 716418076 398221499 591504380 398221499 398221499 591504380 777141390 398221499 591504380 591504380 777141390 287847807 716418076 777141390 716418076 777141390 287847807 287847807 287847807 371028678 371028678 398221499 777141390 371028678 6827702 6827702...
output:
0 0 0 0 29 0 0 0 0 0 0 32 16 0 30 32 24 0 0 0 28 0 0 0 0 5 0 0 0 0 10 0 0 0 9 0 0 0 0 8 0 25 0 0 0 0 18 0 0 0 0 0 4 18 0 19 0 0 0 0 0 0 0 0 37 0 0 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 2 23 0 0 0 20 0 0 23 0 12 0 0 0 0 0 0 0 10 0 0 0 0 0 35 0 0 25 0 0 0 0 22 0 0 0 0 0 0 12 0 0 0 0 94 0 23 0 0 0 0...
result:
wrong answer 1st lines differ - expected: '700', found: '0'