QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#759720 | #9349. Exchanging Gifts | OOBMABTRAMS# | WA | 208ms | 53744kb | C++17 | 1.1kb | 2024-11-18 11:30:57 | 2024-11-18 11:31:01 |
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;
for(int i=1;i<=n;i++)if(!in[i])q.push(i),cnt[i]=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: 7ms
memory: 53744kb
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: 208ms
memory: 53508kb
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:
100 100 100 90 100 100 100 100 100 0 92 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 0 100 100 100 0 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 100 0 100 100 100 100 0 100 100...
result:
wrong answer 1st lines differ - expected: '700', found: '100'