QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743297#8038. Hammer to Fallucup-team3548#RE 2ms8356kbC++201.9kb2024-11-13 18:52:152024-11-13 18:52:21

Judging History

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

  • [2024-11-13 18:52:21]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:8356kb
  • [2024-11-13 18:52:15]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll Inf=1e18+7;
const ll Mod=998244353;
int N,M,Q;
ll A[100001];
struct edge
{
    ll W;
    int Pos;
    ll Num;
    bool operator<(const edge &A)const
    {
        return A.Num<Num;
    }
};
vector<edge>Map[100001];
priority_queue<edge>Queue[100001];
int B[100001];
int Stack[100001],Tot;
bool Vis[100001];
ll DP[100001];
int main()
{
    scanf("%d%d%d",&N,&M,&Q);
    for(int i=1;i<=N;++i)
    scanf("%lld",&A[i]);
    for(int i=1;i<=M;++i)
    {
        int U,V,W;
        scanf("%d%d%d",&U,&V,&W);
        Map[U].push_back((edge){W,V,0});
        Map[V].push_back((edge){W,U,0});
    }
    int Block=sqrt(log2((double)M)*M);
// puts("Here 1");
    for(int i=1;i<=N;++i)
    {
        if(Map[i].size()>=Block)
        {
            Stack[++Tot]=i;
            Vis[i]=true;
            for(int j=0;j<Map[i].size();++j)
            Queue[i].push((edge){Map[i][j].W,Map[i][j].Pos,Map[i][j].W});
        }
    }
    for(int i=1;i<=Q;++i)
    scanf("%d",&B[i]);
// puts("Here 2");
    for(int i=Q;i>0;--i)
    {
        int Pos=B[i];
        if(Vis[Pos])
        {
            edge Top=Queue[Pos].top();
            Queue[Pos].pop();
            while(Top.Num!=DP[Top.Pos]+Top.W)
            {
                Queue[Pos].push((edge){Top.W,Top.Pos,DP[Top.Pos]+Top.W});
                Top=Queue[Pos].top();
            }
            DP[Pos]=Top.Num;
        }
        else
        {
            DP[Pos]=Inf;
            for(int j=0;j<Map[Pos].size();++j)
            {
                int To=Map[Pos][j].Pos;
                ll W=Map[Pos][j].W;
                DP[Pos]=min(DP[Pos],DP[To]+W);
            }
        }
    }
    ll Ans=0;
    for(int i=1;i<=N;++i)
    {
        Ans+=DP[i]%Mod*A[i]%Mod;
    }
    printf("%lld\n",Ans%Mod);
    // return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 8356kb

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: -100
Runtime Error

input:

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

output:


result: