QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625801 | #9349. Exchanging Gifts | Godwang# | WA | 228ms | 34400kb | C++14 | 1.5kb | 2024-10-09 21:04:58 | 2024-10-09 21:04:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n, T, t;
struct Node {
int op, x, y;
} ask[N];
vector<int> a[N];
int len[N];
long long tot[N];
bool vis[N];
priority_queue<int> q;
map<int, long long> mp;
inline int read() {
int s = 0;
char c = getchar();
while (c < '0' || c > '9') {
c = getchar();
}
while (c >= '0' && c <= '9') {
s = s * 10 + c - '0';
c = getchar();
}
return s;
}
int main()
{
ios::sync_with_stdio(false);cin.tie();cout.tie();
cin>>T;
while (T--) {
cin>>n;
for (int i = 1; i <= n; i++) {
cin>>ask[i].op;
if (ask[i].op == 1) {
a[i].clear();
cin>>len[i];
for (int j = 1; j <= len[i]; j++) {
cin>>t;
a[i].push_back(t);
}
}
else {
cin>>ask[i].x>>ask[i].y;
}
}
q.push(n); vis[n] = 1;
tot[n] = 1;
while (!q.empty()) {
int tp = q.top();
q.pop();
if (ask[tp].op == 1) continue;
if (!vis[ask[tp].x]) q.push(ask[tp].x), vis[ask[tp].x] = 1;
if (!vis[ask[tp].y]) q.push(ask[tp].y), vis[ask[tp].y] = 1;
tot[ask[tp].x] += tot[tp];
tot[ask[tp].y] += tot[tp];
}
long long t=0,ans=0;
for (int i = 1; i <= n; i++) {
if (ask[i].op == 2) continue;
ans += tot[i] * len[i];
for (int j = 0; j < len[i]; j++) {
mp[a[i][j]] += tot[i];
}
}
for (map<int,long long>::iterator it=mp.begin();it!=mp.end();it++) {
if (it->second >= ans / 2)t=it->second;
}
if(!t)cout<<ans<<endl;
else cout<<ans*2-t*2<<endl;
mp.clear();
for(int i=1;i<=n;i++)tot[i]=vis[i]=0;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 9ms
memory: 32388kb
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: 228ms
memory: 34400kb
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:
wrong answer 2245th lines differ - expected: '103', found: '104'