Submission #535870

# Submission time Handle Problem Language Result Execution time Memory
535870 2022-03-11T15:09:27 Z __Variatto Toll (BOI17_toll) C++17
100 / 100
454 ms 10296 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int MAX=5e4+10;
const int MAXV=1e9+10;///////////////
int k, n, m, o, a, b, w, wyn[MAX], odl[MAX];
pair<int,int>zap[MAX];
vector<pair<int,int>>g[MAX], g2[MAX];
vector<int> nrzap[MAX];
bool odw[MAX];
priority_queue<pair<int,int>>kol;
void dijkstra(int p){
    while(kol.size()){
        auto v=kol.top();
        kol.pop();
        v.fi*=-1;
        if(odw[v.se]) continue;
        odw[v.se]=true;
        for(auto s: g[v.se])
            if(s.fi/k<=p && odl[s.fi]>v.fi+s.se)
                odl[s.fi]=v.fi+s.se, kol.push({-odl[s.fi], s.fi});
    }
}
void dijkstra2(int l){
    while(kol.size()){
        auto v=kol.top();
        kol.pop();
        v.fi*=-1;
        if(odw[v.se]) continue;
        odw[v.se]=true;
        for(auto s: g2[v.se])
            if(s.fi/k>=l && odl[s.fi]>v.fi+s.se)
                odl[s.fi]=v.fi+s.se, kol.push({-odl[s.fi], s.fi});
    }
}
void rek(int a, int b){
    if(a==b) return;
    int sr=(a+b)/2;
    for(int j=k*sr; j<k*(sr+1); j++){
        for(int i=k*sr; i<k*(b+1); i++)
            odw[i]=false, odl[i]=MAXV;
        kol.push({0, j}), odl[j]=0;
        dijkstra(b);
        for(int i=k*(sr+1)-1; i>=(k*a); i--)
            odw[i]=false, odl[i]=MAXV;
        kol.push({0, j}), odl[j]=0;
        dijkstra2(a);
        for(int i=k*(sr+1)-1; i>=k*a; i--){
            for(auto x:nrzap[i]){
                if(zap[x].se>=k*(sr+1)-1 && zap[x].se<k*(b+1)){
//                    cout<<x<<" "<<zap[x].se<<" "<<i<<"x "<<odl[i]<<" "<<odl[zap[x].se]<<"\n";
                    wyn[x]=min(wyn[x], odl[i]+odl[zap[x].se]);
                }
            }
        }
    }
    rek(a, sr);
    rek(sr+1, b);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>k>>n>>m>>o;
    for(int i=1; i<=m; i++){
        cin>>a>>b>>w;
        g[a].pb({b, w}), g2[b].pb({a, w});
    }
    for(int i=1; i<=o; i++){
        cin>>zap[i].fi>>zap[i].se;
        wyn[i]=MAXV;
        nrzap[zap[i].fi].pb(i);
    }
    rek(0, n/k);
    for(int i=1; i<=o; i++){
        if(wyn[i]==MAXV)
            cout<<-1<<"\n";
        else
            cout<<wyn[i]<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 68 ms 7628 KB Output is correct
2 Correct 3 ms 3796 KB Output is correct
3 Correct 3 ms 3796 KB Output is correct
4 Correct 3 ms 3796 KB Output is correct
5 Correct 3 ms 3864 KB Output is correct
6 Correct 4 ms 3868 KB Output is correct
7 Correct 3 ms 3924 KB Output is correct
8 Correct 49 ms 8268 KB Output is correct
9 Correct 42 ms 8212 KB Output is correct
10 Correct 12 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 7396 KB Output is correct
2 Correct 2 ms 3796 KB Output is correct
3 Correct 2 ms 3796 KB Output is correct
4 Correct 3 ms 3796 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 2 ms 3796 KB Output is correct
7 Correct 5 ms 4260 KB Output is correct
8 Correct 6 ms 4216 KB Output is correct
9 Correct 51 ms 8164 KB Output is correct
10 Correct 301 ms 10144 KB Output is correct
11 Correct 138 ms 8208 KB Output is correct
12 Correct 77 ms 7884 KB Output is correct
13 Correct 375 ms 10156 KB Output is correct
14 Correct 169 ms 8040 KB Output is correct
15 Correct 205 ms 7308 KB Output is correct
16 Correct 185 ms 7400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3792 KB Output is correct
2 Correct 3 ms 3856 KB Output is correct
3 Correct 2 ms 3856 KB Output is correct
4 Correct 2 ms 3856 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 3 ms 3872 KB Output is correct
7 Correct 4 ms 3924 KB Output is correct
8 Correct 10 ms 4124 KB Output is correct
9 Correct 7 ms 3944 KB Output is correct
10 Correct 54 ms 7924 KB Output is correct
11 Correct 141 ms 7936 KB Output is correct
12 Correct 284 ms 9720 KB Output is correct
13 Correct 316 ms 10184 KB Output is correct
14 Correct 212 ms 8908 KB Output is correct
15 Correct 184 ms 7280 KB Output is correct
16 Correct 182 ms 7256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3792 KB Output is correct
2 Correct 3 ms 3856 KB Output is correct
3 Correct 2 ms 3856 KB Output is correct
4 Correct 2 ms 3856 KB Output is correct
5 Correct 2 ms 3796 KB Output is correct
6 Correct 3 ms 3872 KB Output is correct
7 Correct 4 ms 3924 KB Output is correct
8 Correct 10 ms 4124 KB Output is correct
9 Correct 7 ms 3944 KB Output is correct
10 Correct 54 ms 7924 KB Output is correct
11 Correct 141 ms 7936 KB Output is correct
12 Correct 284 ms 9720 KB Output is correct
13 Correct 316 ms 10184 KB Output is correct
14 Correct 212 ms 8908 KB Output is correct
15 Correct 184 ms 7280 KB Output is correct
16 Correct 182 ms 7256 KB Output is correct
17 Correct 128 ms 8068 KB Output is correct
18 Correct 2 ms 3796 KB Output is correct
19 Correct 2 ms 3852 KB Output is correct
20 Correct 3 ms 3856 KB Output is correct
21 Correct 2 ms 3796 KB Output is correct
22 Correct 2 ms 3796 KB Output is correct
23 Correct 4 ms 3996 KB Output is correct
24 Correct 5 ms 4068 KB Output is correct
25 Correct 9 ms 4120 KB Output is correct
26 Correct 8 ms 4088 KB Output is correct
27 Correct 54 ms 8056 KB Output is correct
28 Correct 278 ms 9872 KB Output is correct
29 Correct 293 ms 10212 KB Output is correct
30 Correct 201 ms 8948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 7628 KB Output is correct
2 Correct 3 ms 3796 KB Output is correct
3 Correct 3 ms 3796 KB Output is correct
4 Correct 3 ms 3796 KB Output is correct
5 Correct 3 ms 3864 KB Output is correct
6 Correct 4 ms 3868 KB Output is correct
7 Correct 3 ms 3924 KB Output is correct
8 Correct 49 ms 8268 KB Output is correct
9 Correct 42 ms 8212 KB Output is correct
10 Correct 12 ms 4600 KB Output is correct
11 Correct 152 ms 7396 KB Output is correct
12 Correct 2 ms 3796 KB Output is correct
13 Correct 2 ms 3796 KB Output is correct
14 Correct 3 ms 3796 KB Output is correct
15 Correct 2 ms 3796 KB Output is correct
16 Correct 2 ms 3796 KB Output is correct
17 Correct 5 ms 4260 KB Output is correct
18 Correct 6 ms 4216 KB Output is correct
19 Correct 51 ms 8164 KB Output is correct
20 Correct 301 ms 10144 KB Output is correct
21 Correct 138 ms 8208 KB Output is correct
22 Correct 77 ms 7884 KB Output is correct
23 Correct 375 ms 10156 KB Output is correct
24 Correct 169 ms 8040 KB Output is correct
25 Correct 205 ms 7308 KB Output is correct
26 Correct 185 ms 7400 KB Output is correct
27 Correct 2 ms 3792 KB Output is correct
28 Correct 3 ms 3856 KB Output is correct
29 Correct 2 ms 3856 KB Output is correct
30 Correct 2 ms 3856 KB Output is correct
31 Correct 2 ms 3796 KB Output is correct
32 Correct 3 ms 3872 KB Output is correct
33 Correct 4 ms 3924 KB Output is correct
34 Correct 10 ms 4124 KB Output is correct
35 Correct 7 ms 3944 KB Output is correct
36 Correct 54 ms 7924 KB Output is correct
37 Correct 141 ms 7936 KB Output is correct
38 Correct 284 ms 9720 KB Output is correct
39 Correct 316 ms 10184 KB Output is correct
40 Correct 212 ms 8908 KB Output is correct
41 Correct 184 ms 7280 KB Output is correct
42 Correct 182 ms 7256 KB Output is correct
43 Correct 128 ms 8068 KB Output is correct
44 Correct 2 ms 3796 KB Output is correct
45 Correct 2 ms 3852 KB Output is correct
46 Correct 3 ms 3856 KB Output is correct
47 Correct 2 ms 3796 KB Output is correct
48 Correct 2 ms 3796 KB Output is correct
49 Correct 4 ms 3996 KB Output is correct
50 Correct 5 ms 4068 KB Output is correct
51 Correct 9 ms 4120 KB Output is correct
52 Correct 8 ms 4088 KB Output is correct
53 Correct 54 ms 8056 KB Output is correct
54 Correct 278 ms 9872 KB Output is correct
55 Correct 293 ms 10212 KB Output is correct
56 Correct 201 ms 8948 KB Output is correct
57 Correct 454 ms 10296 KB Output is correct
58 Correct 58 ms 8308 KB Output is correct
59 Correct 135 ms 8340 KB Output is correct