QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196434#6523. Escape Planucup-team870#AC ✓328ms43196kbC++141.4kb2023-10-01 17:24:212023-10-01 17:24:21

Judging History

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

  • [2023-10-01 17:24:21]
  • 评测
  • 测评结果:AC
  • 用时:328ms
  • 内存:43196kb
  • [2023-10-01 17:24:21]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N=1e5+5,inf=1e9+7;
vector<P>tu[N];
int d[N];
priority_queue<int>q[N];
void slv(){
    int n,m,k; cin>>n>>m>>k;
    priority_queue<P,vector<P>, greater<P> >Q;
    vector<int>vis(n+1),ok(n+1);
    rep(i,1,n){
        tu[i].clear(); //dis[i]=inf;
        while(q[i].size())q[i].pop();
    }
    rep(i,1,k){
        int x;cin>>x; Q.push({0,x}); //dis[x]=0;
    }
    rep(i,1,n)cin>>d[i];
    rep(i,1,m){
        int u,v,w;cin>>u>>v>>w;
        tu[u].push_back({v,w}); tu[v].push_back({u,w});
    }
    while(Q.size()){
        auto [val,now]=Q.top(); Q.pop();
        if(vis[now])continue;
        // cout<<now<<'h'<<val<<endl;
        if(now==1){
            cout<<val<<'\n';return;
        }
        vis[now]=1;
        for(auto [son,w]:tu[now]){
            if(vis[son])continue;
            int nv=val+w;
            if(q[son].size()>d[son]){
                if(q[son].top()>nv){
                    q[son].pop(); q[son].push(nv);
                }
            }
            else q[son].push(nv);
            if(q[son].size()>d[son]){
                Q.push({q[son].top(),son});
            }
        }
    }
    cout<<"-1\n";
}
int main() {
    IOS
    int T;cin>>T;
    while(T--)slv();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 9476kb

input:

2
3 4 1
3
1 1 1
1 2 1
1 2 2
2 3 1
2 3 2
3 2 2
2 3
2 0 0
1 2 1
1 3 1

output:

4
-1

result:

ok 2 number(s): "4 -1"

Test #2:

score: 0
Accepted
time: 328ms
memory: 43196kb

input:

100
100 1808 2
94 47
3 3 0 2 4 3 3 4 0 0 2 2 2 3 2 4 0 2 3 4 4 2 0 3 4 3 1 0 2 1 2 2 0 3 4 4 4 1 2 2 3 1 0 0 3 1 4 2 1 3 3 4 3 0 4 1 0 3 2 1 4 4 1 3 2 3 3 3 3 1 0 3 0 4 3 1 0 4 0 4 4 1 2 0 0 4 1 3 3 3 0 2 2 1 1 2 3 4 1 2
72 29 1138
59 78 2398
95 5 1610
32 46 4176
36 99 8143
100 69 413
61 58 1595
9 9...

output:

5109
1021
3293
4646
3796
3394
1884
6772
2329
2067
3296
2809
865
4249
2241
3792
2135
2544
3343
1775
10602
4677
1700
2150
7071
14055
3368
2322
1113
1980
3067
1617
1702
-1
2879
6265
2065
2810
2289
3001
402
3769
18118
6874
7879
3823
-1
510
2636
10564
-1
3166
3615
7526
5549
1261
3302
270
4440
1998
3350
3...

result:

ok 100 numbers