QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#759728#9349. Exchanging GiftsOOBMABTRAMS#WA 3ms54444kbC++171.1kb2024-11-18 11:33:442024-11-18 11:33:46

Judging History

你现在查看的是最新测评结果

  • [2024-11-18 11:33:46]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:54444kb
  • [2024-11-18 11:33:44]
  • 提交

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();
}

詳細信息

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'