Submission #918017

# Submission time Handle Problem Language Result Execution time Memory
918017 2024-01-29T11:54:14 Z imarn Robot (JOI21_ho_t4) C++14
100 / 100
1147 ms 83308 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define vp vector<pii>
using namespace std;
const int N=1e5+5;
ll d[N];
map<int,vector<pll>>g[N];
map<int,ll>sum[N];
map<ll,ll>dp[N];
int main(){
    int n,m;cin>>n>>m;
    while(m--){
        int a,b,c,d;cin>>a>>b>>c>>d;
        g[a][c].pb({b,d});
        g[b][c].pb({a,d});
        sum[a][c]+=d;sum[b][c]+=d;
    }d[1]=0;for(int i=2;i<=n;i++)d[i]=1e18;
    priority_queue<pair<pll,int>,vector<pair<pll,int>>,greater<pair<pll,int>>>q;
    q.push({{d[1],1},0});
    while(!q.empty()){
        auto u=q.top();q.pop();
        if(u.s){
            if(dp[u.f.s][u.s]!=u.f.f)continue;
            for(auto v:g[u.f.s][u.s]){
                if(d[v.f]>u.f.f+sum[u.f.s][u.s]-v.s){
                    d[v.f]=u.f.f+sum[u.f.s][u.s]-v.s;
                    q.push({{d[v.f],v.f},0});
                }
            }
        }else {
            if(d[u.f.s]!=u.f.f)continue;
            for(auto it : g[u.f.s]){
                for(auto v:it.s){
                    if(d[v.f]>u.f.f+min(v.s,sum[u.f.s][it.f]-v.s)){
                        d[v.f]=u.f.f+min(v.s,sum[u.f.s][it.f]-v.s);
                        q.push({{d[v.f],v.f},0});
                    }
                    if(dp[v.f].find(it.f)==dp[v.f].end()||dp[v.f][it.f]>u.f.f){
                        dp[v.f][it.f]=u.f.f;q.push({{dp[v.f][it.f],v.f},it.f});
                    }
                }
            }
        }
    }cout<<(d[n]>=1e18?-1:d[n]);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 4 ms 15192 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14936 KB Output is correct
5 Correct 4 ms 15024 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 5 ms 14940 KB Output is correct
8 Correct 4 ms 15036 KB Output is correct
9 Correct 8 ms 15452 KB Output is correct
10 Correct 7 ms 15452 KB Output is correct
11 Correct 6 ms 15244 KB Output is correct
12 Correct 5 ms 15196 KB Output is correct
13 Correct 6 ms 15196 KB Output is correct
14 Correct 5 ms 15240 KB Output is correct
15 Correct 6 ms 15192 KB Output is correct
16 Correct 6 ms 15192 KB Output is correct
17 Correct 5 ms 15196 KB Output is correct
18 Correct 4 ms 14980 KB Output is correct
19 Correct 6 ms 15196 KB Output is correct
20 Correct 6 ms 15240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 254 ms 33564 KB Output is correct
2 Correct 74 ms 24504 KB Output is correct
3 Correct 230 ms 29636 KB Output is correct
4 Correct 123 ms 27144 KB Output is correct
5 Correct 1147 ms 79704 KB Output is correct
6 Correct 924 ms 70008 KB Output is correct
7 Correct 442 ms 51904 KB Output is correct
8 Correct 501 ms 47120 KB Output is correct
9 Correct 557 ms 46928 KB Output is correct
10 Correct 382 ms 45824 KB Output is correct
11 Correct 185 ms 32084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 4 ms 15192 KB Output is correct
3 Correct 3 ms 14940 KB Output is correct
4 Correct 3 ms 14936 KB Output is correct
5 Correct 4 ms 15024 KB Output is correct
6 Correct 4 ms 14940 KB Output is correct
7 Correct 5 ms 14940 KB Output is correct
8 Correct 4 ms 15036 KB Output is correct
9 Correct 8 ms 15452 KB Output is correct
10 Correct 7 ms 15452 KB Output is correct
11 Correct 6 ms 15244 KB Output is correct
12 Correct 5 ms 15196 KB Output is correct
13 Correct 6 ms 15196 KB Output is correct
14 Correct 5 ms 15240 KB Output is correct
15 Correct 6 ms 15192 KB Output is correct
16 Correct 6 ms 15192 KB Output is correct
17 Correct 5 ms 15196 KB Output is correct
18 Correct 4 ms 14980 KB Output is correct
19 Correct 6 ms 15196 KB Output is correct
20 Correct 6 ms 15240 KB Output is correct
21 Correct 254 ms 33564 KB Output is correct
22 Correct 74 ms 24504 KB Output is correct
23 Correct 230 ms 29636 KB Output is correct
24 Correct 123 ms 27144 KB Output is correct
25 Correct 1147 ms 79704 KB Output is correct
26 Correct 924 ms 70008 KB Output is correct
27 Correct 442 ms 51904 KB Output is correct
28 Correct 501 ms 47120 KB Output is correct
29 Correct 557 ms 46928 KB Output is correct
30 Correct 382 ms 45824 KB Output is correct
31 Correct 185 ms 32084 KB Output is correct
32 Correct 196 ms 27476 KB Output is correct
33 Correct 194 ms 30412 KB Output is correct
34 Correct 536 ms 49288 KB Output is correct
35 Correct 379 ms 40740 KB Output is correct
36 Correct 391 ms 46028 KB Output is correct
37 Correct 500 ms 49076 KB Output is correct
38 Correct 472 ms 60084 KB Output is correct
39 Correct 218 ms 30512 KB Output is correct
40 Correct 582 ms 49764 KB Output is correct
41 Correct 563 ms 49940 KB Output is correct
42 Correct 663 ms 59280 KB Output is correct
43 Correct 212 ms 36516 KB Output is correct
44 Correct 436 ms 41156 KB Output is correct
45 Correct 408 ms 45972 KB Output is correct
46 Correct 380 ms 46380 KB Output is correct
47 Correct 401 ms 48632 KB Output is correct
48 Correct 1127 ms 83308 KB Output is correct