QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#575809 | #9349. Exchanging Gifts | lqh2024# | WA | 301ms | 3616kb | C++20 | 1.2kb | 2024-09-19 16:51:42 | 2024-09-19 16:51:46 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve() {
int n;
cin >> n;
vector<map<int, int>> mp(n + 1);
vector<vector<int>> adj(n + 1);
vector<int> in(n + 1);
for (int i = 1; i <= n; i++) {
int op;
cin >> op;
if (op == 1) {
int k;
cin >> k;
for (int j = 1; j <= k; j++) {
int x;
cin >> x;
mp[i][x]++;
}
} else {
int x, y;
cin >> x >> y;
adj[i].push_back(x);
adj[i].push_back(y);
in[x]++;
in[y]++;
}
}
queue<int> q;
q.push(n);
vector<int> f(n + 1);
f[n] = 1;
while (q.size()) {
int u = q.front();
q.pop();
for (int v : adj[u]) {
f[v] += f[u];
in[v]--;
if (!in[v]) {
q.push(v);
}
}
}
map<int, int> cnt;
int tot = 0;
for (int i = 1; i <= n; i++) {
for (auto [u, v] : mp[i]) {
tot += f[i] * v;
cnt[u] += f[i] * v;
}
}
int mx = 0;
for (auto [u, v] : cnt) {
mx = max(mx, v);
}
if (mx <= tot / 2) {
cout << tot << "\n";
} else {
cout << tot - (mx - tot / 2) << "\n";
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while (T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3616kb
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: 301ms
memory: 3576kb
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 11 0 0 24 0 0 35 0 0 25 0 0 0 0 22 0 0 0 0 21 0 13 0 0 0 0 94 0 23 0 0 0...
result:
wrong answer 1st lines differ - expected: '700', found: '0'