QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#759730 | #9349. Exchanging Gifts | OOBMABTRAMS# | WA | 200ms | 54308kb | C++17 | 1.1kb | 2024-11-18 11:34:24 | 2024-11-18 11:34:27 |
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);cnt[n]=1;
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: 100
Accepted
time: 4ms
memory: 54308kb
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: 200ms
memory: 53480kb
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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
wrong answer 1st lines differ - expected: '700', found: '0'