QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#759728 | #9349. Exchanging Gifts | OOBMABTRAMS# | WA | 3ms | 54444kb | C++17 | 1.1kb | 2024-11-18 11:33:44 | 2024-11-18 11:33:46 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int N=1000013;
const int P=1e9+7;
typedef long long ll;
typedef long double ld;
vector<int>f[N],g[N];
ll cnt[N];int in[N];
void solve(){
int n;
cin>>n;
for(int i=1;i<=n;i++)f[i].clear(),cnt[i]=in[i]=0,g[i].clear();
for(int i=1;i<=n;i++) {
int o,x,y;
cin>>o;
if(o==1) {
cin>>x;
while(x--)cin>>y,f[i].push_back(y);
}else {
cin>>x>>y,g[i].push_back(x),g[i].push_back(y),in[x]++,in[y]++;
}
}
queue<int>q;q.push(n);
while(!q.empty()) {
int x=q.front();
q.pop();
for(auto i:g[x]) {
if(!--in[i])cnt[i]+=cnt[x],q.push(i);
}
}
map<int,ll>cnt2;
for(int i=1;i<=n;i++)for(auto c:f[i])cnt2[c]+=cnt[i];
ll mx=0,tot=0;
for(auto[x,y]:cnt2)mx=max(mx,y),tot+=y;
cout<<min((tot-mx)*2,tot)<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T=1;cin>>T;
while(T--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 54444kb
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:
0 0
result:
wrong answer 1st lines differ - expected: '4', found: '0'