QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#661138 | #9349. Exchanging Gifts | ganking# | WA | 152ms | 9864kb | C++20 | 1.4kb | 2024-10-20 14:53:07 | 2024-10-20 14:53:08 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define db long double
#define mk make_pair
#define eb emplace_back
#define fo(i,a,b) for(ll (i)=(a);(i)<=(b);(i)++)
#define fd(i,a,b) for(ll (i)=(a);(i)>=(b);(i)--)
using namespace std;
const int N=1e6+10;
const int mo=1e9+7;
ll n,op[N],k,x,y,d[N],f[N];
vector<int> e[N],p[N];
queue<int> q;
map<int,ll> mp;
void solve(){
cin>>n;
fo(i,1,n) f[i]=d[i]=0,e[i].clear(),p[i].clear();
fo(i,1,n)
{
cin>>op[i];
if(op[i]==1){
cin>>k;
fo(j,1,k) cin>>x,p[i].eb(x);
}
else {
cin>>x>>y;
d[x]++;d[y]++;
e[i].eb(x);
e[i].eb(y);
}
}
q.push(n); f[n]=1;
while(!q.empty()){
int x=q.front();q.pop();
for(auto y:e[x]){
d[y]--;
f[y]+=f[x];
if(d[y]==0){
q.push(y);
}
}
}
mp.clear();
ll ans=0,len=0;
fo(i,1,n){
// cout<<f[i]<<"\n";
if(f[i] && op[i]==1){
for(auto y:p[i]) mp[y]+=f[i];
len+=f[i]*p[i].size();
}
}
for(auto it:mp) {
ans=max(ans,it.second);
}
if(ans*2>=len) cout<<2*(len-ans)<<"\n";
else cout<<len<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.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: 3ms
memory: 9732kb
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: 152ms
memory: 9864kb
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'