QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#629658 | #9349. Exchanging Gifts | yumingsk | WA | 400ms | 73268kb | C++14 | 2.6kb | 2024-10-11 14:06:01 | 2024-10-11 14:06:02 |
Judging History
answer
#pragma GCC optimize(3, "Ofast", "inline")
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define L_INF 0x7f3f3f3f3f3f3f3f
#define db cout << "debug\n";
using namespace std;
const int Mod = 998244353;
using ll = long long;
vector<int> e[1000005];
vector<int> sq[1000000 + 1];
int deg[1000005];
map<int, int> ma;
vector<ll> tp(1000005);
int vis[1000005];
int n;
void bfs(int u)
{
queue<int> q;
for (int i = 1; i <= n; i++)
{
if (deg[i] == 0)
{
q.push(i);
if (i == n)
tp[i] = 1;
}
}
while (!q.empty())
{
int t = q.front();
q.pop();
// cout << t << '\n';
for (auto v : e[t])
{
// cout << v << '\n';
tp[v] += tp[t];
deg[v]--;
if (deg[v] == 0)
{
q.push(v);
}
}
}
return;
}
void solve()
{
cin >> n;
for (int i = 1; i <= n + 1; i++)
e[i].clear(), sq[i].clear(), tp[i] = 0, deg[i] = 0, vis[i] = 0;
ma.clear();
for (int i = 1; i <= n; i++)
{
int op;
cin >> op;
if (op == 1)
{
int len;
cin >> len;
sq[i].resize(len);
for (int j = 1; j <= len; j++)
{
int x;
cin >> x;
sq[i][j - 1] = x;
}
}
else
{
int x, y;
cin >> x >> y;
e[i].push_back(x);
e[i].push_back(y);
deg[x]++;
deg[y]++;
}
}
// cout << "SS\n";
ll sum = 0;
ll mx = 0;
bfs(n);
for (int i = 1; i <= n; i++)
{
if (!sq[i].empty() && tp[i] > 0)
{
for (auto v : sq[i])
ma[v] += tp[i];
}
}
for (auto v : ma)
{
sum += v.second;
mx = max(mx, v.second * 1LL);
}
// cout << sum << " " << mx << '\n';
if (mx > sum - mx)
{
cout << 2LL * (sum - mx) << '\n';
}
else
{
cout << sum << '\n';
}
}
int main()
{
IOS;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#ifndef ONLINE_JUDGE
clock_t start_time = clock();
#endif
int t = 1;
cin >> t;
while (t--)
{
solve();
}
#ifndef ONLINE_JUDGE
cout << "Used " << (double)(clock() - start_time) << " ms" << endl;
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 7ms
memory: 60976kb
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: 0
Accepted
time: 191ms
memory: 61472kb
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:
700 68 332 284 131 1048 194 667 704 0 484 252 35 351 1228 238 1025 354 383 571 4272 340 1044 199 448 190 0 69 841 546 247 883 138 1633 91 3308 2556 1280 488 618 407 381 383 2865 0 496 1202 53 0 415 662 380 41 18 91 505 818 603 241 764 1227 1802 176 187 817 1489 460 296 238 236 1028 0 606 1696 746 10...
result:
ok 10000 lines
Test #3:
score: 0
Accepted
time: 205ms
memory: 60488kb
input:
1000 1000 1 95 626416845 75969860 75969860 75969860 75969860 75969860 626416845 75969860 626416845 626416845 626416845 626416845 75969860 75969860 75969860 626416845 75969860 626416845 626416845 75969860 626416845 75969860 75969860 626416845 75969860 626416845 626416845 75969860 75969860 75969860 62...
output:
7496 113951 17628 151136 92998 49984 39422 57746 0 28271 27458 0 127054 13854 68249 32166 280419 70120 0 0 47941 71104 93032 21042 30012 0 0 14482 20938 66600 94605 129973 145603 16366 43924 0 9923 18731 0 249292 8847 30154 288759 0 86256 30372 156418 247862 91672 38330 89806 27911 137951 166924 189...
result:
ok 1000 lines
Test #4:
score: 0
Accepted
time: 226ms
memory: 62284kb
input:
100 10000 1 1354 265069553 265069553 729542591 729542591 729542591 729542591 729542591 729542591 729542591 265069553 265069553 265069553 729542591 729542591 265069553 729542591 265069553 729542591 265069553 729542591 265069553 265069553 265069553 265069553 265069553 265069553 729542591 265069553 265...
output:
2156412 5940042 1932718 2497609 3287092 0 5176818 7057040 26127674 6268925 0 3298524 6134142 0 0 0 2293094 0 67966 0 708927 0 3540522 205067 0 791702 3283922 0 5278171 8734406 3719656 0 5635776 3559716 0 5795392 4238756 1752825 0 17244508 398074 0 12989840 0 0 849320 211188 545453 4409794 0 4164304 ...
result:
ok 100 lines
Test #5:
score: 0
Accepted
time: 284ms
memory: 72076kb
input:
10 100000 1 11020 495408904 495408904 377631092 377631092 377631092 377631092 495408904 377631092 377631092 377631092 495408904 377631092 495408904 495408904 377631092 495408904 495408904 495408904 377631092 495408904 377631092 495408904 377631092 495408904 495408904 495408904 495408904 377631092 49...
output:
306812544 192374690 0 0 19322750 795133717 1281613237 77446187 657488136 227127642
result:
ok 10 lines
Test #6:
score: -100
Wrong Answer
time: 400ms
memory: 73268kb
input:
10 100000 1 10000 721377195 837302194 866508535 947346285 36266706 885676668 931769731 950140113 336739676 477767858 708236246 553944300 378949767 850666110 754246821 53462385 667372368 691425789 878638555 396531344 888905673 113446879 829163879 489125321 788813861 642102926 385958067 714854335 6508...
output:
20521353740288 19834158972928 -54120854355878 -52974098082148 -38590248954968 12292196401152 -117857892968800 51934744543232 19597935771648 -55701259800750
result:
wrong answer 1st lines differ - expected: '535195874754560000', found: '20521353740288'