QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#359430#410. Telegraphnew_acc20 2ms9872kbC++202.0kb2024-03-20 17:47:162024-03-20 17:47:17

Judging History

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

  • [2024-03-20 17:47:17]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:9872kb
  • [2024-03-20 17:47:16]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define pitem item*
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=1e6+10;
const int SS=1<<19;
const int INFi=2e9;
const ll INFl=1e16;
const ll mod2=998244353;
const ll mod=1e9+7;
const ll mod3=2027865967;
const ll p=70032301;
const ull p2=913;
const int L=20;
int t[N],n,dkg[N],li,sp[N];
ll mini[N];
vi curr,graf[N];
bool vis[N],vis2[N],nn[N];
void dfs(int v){
    if(vis2[v]){
        sp[v]=++li;
        nn[v]=1;
        for(int i=curr.size()-1;curr[i]!=v;i--){
            nn[curr[i]]=1;
        }
        return;
    }
    if(vis[v]) return;
    vis[v]=1,vis2[v]=1;
    curr.push_back(v);
    dfs(dkg[v]); 
    sp[v]=sp[dkg[v]];
    curr.pop_back();
    vis2[v]=0;
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>dkg[i]>>t[i];
        graf[dkg[i]].push_back(t[i]);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i); 
        } 
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        sort(graf[i].begin(),graf[i].end());
        if(!nn[i]){
            for(int i2=0;i2<(int)graf[i].size()-1;i2++){
                ans+=graf[i][i2];
            }
        } 
    }
    for(int i=1;i<=li;i++) mini[i]=INFl;
    for(int i=1;i<=n;i++){
        if(!nn[i]) continue;
        ll ile=0,ost=0;
        bool byl=0;
        for(auto u:graf[dkg[i]]){
            if(u==t[i] and !byl){
                byl=1;
                continue;
            } 
            ile+=u;
            ost=u;
        }
        ile+=t[i];
        ile-=ost;
        ll ile2=0;
        for(auto u:graf[dkg[i]]){
            ile2+=u;
        }
        ile2-=graf[dkg[i]][graf[dkg[i]].size()-1];
        ans+=ile2;
        mini[sp[i]]=min(mini[sp[i]],ile-ile2);
    }
    for(int i=1;i<=li;i++) ans+=mini[i];
    cout<<ans<<"\n";
}
int main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    int tt=1;
    while(tt--) solve();
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 0ms
memory: 9792kb

input:

10
3 85377744
3 191391530
4 553475509
8 344887257
9 812158120
1 880268352
4 686078706
7 182546394
4 220137367
3 89957933

output:

1081551750

result:

ok single line: '1081551750'

Test #2:

score: 0
Accepted
time: 2ms
memory: 9844kb

input:

10
3 688989554
5 112566798
1 294281317
1 96941112
6 746415334
2 612836992
9 629868215
1 406822326
10 638640051
8 199983696

output:

503789227

result:

ok single line: '503789227'

Test #3:

score: 0
Accepted
time: 2ms
memory: 9840kb

input:

10
3 292601364
7 33742065
7 35087125
3 996478615
4 828156197
3 197921984
8 426174077
4 631098259
5 57142735
5 457493107

output:

1212506407

result:

ok single line: '1212506407'

Test #4:

score: 0
Accepted
time: 2ms
memory: 9872kb

input:

10
6 43696822
9 954917333
7 923376581
5 896016118
1 762413411
4 930490625
3 369963586
9 855374192
2 475645419
1 567518871

output:

1936096612

result:

ok single line: '1936096612'

Test #5:

score: 0
Accepted
time: 2ms
memory: 9732kb

input:

10
6 647308632
3 876092601
4 664182389
6 648069973
7 844154274
5 663059265
1 166269448
3 79650124
7 894148102
7 825028282

output:

2396141312

result:

ok single line: '2396141312'

Test #6:

score: -10
Wrong Answer
time: 0ms
memory: 9792kb

input:

10
5 415342264
1 248144257
7 494844360
9 110058957
4 614196536
3 303926057
10 44559777
2 165167138
6 41487942
8 935054045

output:

41487942

result:

wrong answer 1st lines differ - expected: '0', found: '41487942'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%