QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#525#317894#8038. Hammer to Fallship2077ship2077Failed.2024-01-29 22:07:422024-01-29 22:07:42

詳細信息

Extra Test:

Invalid Input

input:

3 3 3
1 1 1
1 2 1
1 2 2
2 3 1
1
2
3

output:


result:

FAIL muti edges

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#317894#8038. Hammer to Fallship2077RE 626ms710352kbC++141.4kb2024-01-29 21:42:222024-01-30 14:24:09

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int M=1e5+5,mod=998244353;
tuple<ll,int,int>res[500][M];
int n,m,q,x,y,z,ans,tot,block;
vector<pair<int,int>>g[M];ll dp[M];
int a[M],p[M],id[M],vec[M];
int read(){
    int x=0;char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
    return x;
}
void solve(int ql,int qr){
    for (int k=1;k<=tot;k++){ int x=vec[k],siz=0;
        for (auto [y,z]:g[x]) res[k][++siz]={dp[y]+z,y,z};
    	nth_element(res[k]+1,res[k]+block,res[k]+siz+1);
    }
    for (int i=qr;i>=ql;i--){
        int x=p[i];dp[x]=1ll<<60;
        if (g[x].size()<=block)
            for (auto [y,z]:g[x])
                dp[x]=min(dp[x],dp[y]+z);
        else for (int j=1;j<=block;j++)
            dp[x]=min(dp[x],dp[get<1>(res[id[x]][j])]+get<2>(res[id[x]][j]));
    }
}
int main(){
    n=read();m=read();q=read();
    for (int i=1;i<=n;i++) a[i]=read();
    for (int i=1;i<=m;i++){
        x=read();y=read();z=read();
        g[x].push_back({y,z});
        g[y].push_back({x,z});
    }
    block=(int)ceil(sqrt(m));
    for (int i=1;i<=n;i++)
        if (g[i].size()>block)
            vec[++tot]=i,id[i]=tot;
    for (int i=1;i<=q;i++) p[i]=read();
    for (int i=q;i>0;i-=block) solve(max(i-block,0)+1,i);
    for (int i=1;i<=n;i++) ans=(ans+dp[i]%mod*a[i])%mod;
    printf("%d\n",ans);
    return 0;
}