QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#759733#9349. Exchanging GiftsOOBMABTRAMS#WA 209ms54524kbC++171.3kb2024-11-18 11:36:362024-11-18 11:36:38

Judging History

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

  • [2024-11-18 11:36:38]
  • 评测
  • 测评结果:WA
  • 用时:209ms
  • 内存:54524kb
  • [2024-11-18 11:36:36]
  • 提交

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);
    while(!q.empty()) {
        int x=q.front();
        q.pop();
        for(auto i:g[x]) {
            if(!--in[i])cnt[i]+=cnt[x],q.push(i);
        }
    }
    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();
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 54524kb

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: 209ms
memory: 54328kb

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:

52
2
55
86
70
41
66
94
96
0
62
60
17
70
100
100
100
79
65
83
99
60
36
59
48
49
0
42
55
100
87
89
58
58
70
87
72
78
86
58
57
31
93
99
0
89
93
43
0
88
65
38
41
18
79
51
70
15
60
87
64
93
76
100
99
94
41
81
92
50
48
0
40
36
59
97
0
26
29
0
71
84
55
60
0
87
29
34
95
99
68
99
74
0
72
47
0
58
100
12
51
10...

result:

wrong answer 1st lines differ - expected: '700', found: '52'