QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#109884#6523. Escape PlanZeardoeAC ✓1405ms93904kbC++202.3kb2023-05-30 21:25:582023-05-30 21:25:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-30 21:25:59]
  • 评测
  • 测评结果:AC
  • 用时:1405ms
  • 内存:93904kb
  • [2023-05-30 21:25:58]
  • 提交

answer

/*
[templates]: 
duipai
spjdp
compre
addhis
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
//use ll instead of int.
#define f(i, a, b) for(int i = (a); i <= (b); i++)
#define cl(i, n) i.clear(),i.resize(n);
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e15;
//#define cerr if(false)cerr
//#define freopen if(false)freopen
mt19937 rng(time(0)); 
int rnd(int l, int r) {return rng() % (r-l+1) + l; }
#define watch(x) cerr  << (#x) << ' '<<'i'<<'s'<<' ' << x << endl
void pofe(int number, int bitnum) {
    string s; f(i, 0, bitnum) {s += char(number & 1) + '0'; number >>= 1; } 
    reverse(s.begin(), s.end()); cerr << s << endl; 
    return;
}
template <typename TYP> void cmax(TYP &x, TYP y) {if(x < y) x = y;}
template <typename TYP> void cmin(TYP &x, TYP y) {if(x > y) x = y;}
//调不出来给我对拍!
//use std::array.
int d[100010];vector<pii>g[100010]; int dep[100010];int deg[100010];
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen();
    //freopen();
    //time_t start = clock();
    //think twice,code once.
    //think once,debug forever.
    int T; cin >> T;
    while(T--) {
        int n,m,k;cin>>n>>m>>k;f(i,1,n)g[i].clear(),dep[i]=inf,deg[i]=0;
        vector<int>e;
        f(i,1,k){int _; cin>>_; e.push_back(_);}
        f(i,1,n)cin>>d[i];
        f(i,1,m){int u,v,w;cin>>u>>v>>w;g[u].push_back({v,w});g[v].push_back({u,w});}
        priority_queue<pii>q; for(int i:e){q.push({0,i});d[i]=0;}
        while(!q.empty()) { //这里有点疑问,pq 能否这么用
            pii it = q.top(); int cost=-it.first, now=it.second;q.pop();
            //cerr<<deg[now]<<" "<<d[now]<<endl;
            if(deg[now]==d[now]+1)continue;
            deg[now]++; 
            if(deg[now]==d[now]+1) {
                dep[now]=cost;
         //       cerr<<now<<" "<<cost<<endl;
                for(pii jt : g[now]) {
                    int v=jt.first,w=jt.second;
                    q.push({-cost-w,v});
                }
            }
        }
        cout<<(dep[1]<inf?dep[1]:-1)<<endl;
    }
    //time_t finish = clock();
    //cout << "time used:" << (finish-start) * 1.0 / CLOCKS_PER_SEC <<"s"<< endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 6004kb

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: 1405ms
memory: 93904kb

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