QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#734935#8038. Hammer to Fallwater_tomatoTL 199ms80756kbC++142.2kb2024-11-11 16:07:572024-11-11 16:07:58

Judging History

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

  • [2024-11-11 16:07:58]
  • 评测
  • 测评结果:TL
  • 用时:199ms
  • 内存:80756kb
  • [2024-11-11 16:07:57]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define pi pair<int,int>
using namespace std;
const int N=5e5+5;
struct node{
    int to,nxt,w;
}e[N];
int head[N],cnt;
void add(int u,int v,int w){
    e[++cnt]={v,head[u],w};
    head[u]=cnt;
}
int n,q,m;
int a[N],b[N],val[N];
set<pi> s[N];
int du[N];
int LIM=100;
bool heavy[N];
vector<pi> h_edge[N],path;
const int mod=998244353;
map<pi,int> dis;
signed main(){
    scanf("%lld%lld%lld",&n,&m,&q);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1,u,v,w;i<=m;i++){
        scanf("%lld%lld%lld",&u,&v,&w);
        du[u]++;du[v]++;
        add(u,v,w);add(v,u,w);
        dis[{u,v}]=dis[{v,u}]=w;
    }
    for(int i=1;i<=n;i++){
        if(du[i]>=LIM) heavy[i]=1;
    }
    for(int u=1;u<=n;u++){
        for(int i=head[u];i;i=e[i].nxt){
            int v=e[i].to;
            if(heavy[v]) h_edge[u].push_back({e[i].w,v});
            else{
                s[u].insert({e[i].w,v});
            }
        }
    }
    for(int i=1;i<=q;i++) scanf("%lld",&b[i]);
    for(int i=q;i>=1;i--){
        int u=b[i];
        int ori=val[u];
        int minv=-1,minn=1e18;
        // printf("%d:\n",u);
        for(auto x:h_edge[u]){
            // printf("? %d %d\n",x.first,x.second);
            if(x.first+val[x.second]<minn){
                minn=x.first+val[x.second];
                minv=x.second;
            }
        }

        if(!s[u].empty()){
            auto x=*s[u].begin();
            if(x.first<minn){
                minn=x.first;
                minv=x.second;
            }    
        }
        
        path.push_back({u,minv});

        if(heavy[u]){
            val[u]=minn;
        }
        else{
            val[u]=minn;
            for(int j=head[u];j;j=e[j].nxt){
                int v=e[j].to;
                s[v].erase({ori+e[j].w,u});
                s[v].insert({e[j].w+val[u],u});
            }
        }
    }
    long long ans=0;
    for(int i=path.size()-1;i>=0;i--){
        int u=path[i].first,v=path[i].second;
        ans=(ans+a[u]*dis[{u,v}])%mod;
        a[v]=(a[v]+a[u])%mod;a[u]=0;
        // printf("! %d %d\n",path[i].first,path[i].second);
    }
    printf("%lld\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 9ms
memory: 49664kb

input:

3 2 2
1 1 1
2 3 10
1 2 1
3 2

output:

12

result:

ok single line: '12'

Test #2:

score: 0
Accepted
time: 4ms
memory: 49800kb

input:

2 1 10
5000 5000
1 2 10000
1 2 2 1 2 2 1 1 1 2

output:

550000000

result:

ok single line: '550000000'

Test #3:

score: 0
Accepted
time: 4ms
memory: 49704kb

input:

10 10 10
5 14 99 14 18 4 58 39 48 60
2 4 4
6 9 56
10 8 34
7 5 96
1 3 26
3 7 92
6 8 4
5 1 72
7 6 39
7 2 93
8 8 9 10 2 2 5 9 2 3

output:

8810

result:

ok single line: '8810'

Test #4:

score: 0
Accepted
time: 19ms
memory: 50824kb

input:

100 500 10000
89 61 65 85 89 2 32 97 13 70 29 86 68 74 84 64 54 39 26 84 56 95 73 11 70 26 60 40 84 58 68 33 65 71 55 2 11 71 49 85 14 59 38 11 60 8 81 78 27 32 52 49 35 94 62 72 64 50 12 45 77 74 92 67 92 38 81 39 12 29 60 70 53 33 25 60 7 83 4 85 47 32 13 58 85 86 44 68 44 1 81 62 97 7 66 62 5 16 ...

output:

609241

result:

ok single line: '609241'

Test #5:

score: 0
Accepted
time: 199ms
memory: 80756kb

input:

100000 100000 100000
134299012 740620432 241626312 533601686 901212368 274154852 46613593 72208460 685661661 930069933 934386896 140544225 900179749 8735320 54649110 922673925 450551589 517879800 773426781 410723403 783459037 344315202 75310230 122339501 113898579 646500753 18238713 119326471 969272...

output:

641103242

result:

ok single line: '641103242'

Test #6:

score: 0
Accepted
time: 169ms
memory: 75304kb

input:

448 100000 100000
411038009 847809848 901622409 143987890 230747977 330204397 58948994 635255827 124637955 446506876 693363517 282765360 687916399 598850473 404480258 958197468 332242997 7338874 321860348 37384562 440321061 434694843 935461053 803393359 852456369 428568442 233194935 663299156 907095...

output:

571525504

result:

ok single line: '571525504'

Test #7:

score: 0
Accepted
time: 159ms
memory: 73996kb

input:

800 100000 100000
251326676 820687742 668136087 685815400 271616099 930730049 622254842 263896849 496882119 842365233 827598659 952040530 71490970 870970052 583387021 380241141 573355930 302234935 73043289 694595013 308355368 412222215 132076042 970688532 157167052 932138361 941436777 33081400 29786...

output:

127243876

result:

ok single line: '127243876'

Test #8:

score: -100
Time Limit Exceeded

input:

2500 100000 100000
906300804 27973131 291731361 13136711 330409907 278210346 97382525 517930303 140685227 76822227 543248915 363117785 379028542 906572814 130403111 29847389 693506370 592704644 989452223 269178614 114603023 108858627 613364646 303414069 537766403 972627965 512287469 938256271 272592...

output:

922000064

result: