Submission #535634

# Submission time Handle Problem Language Result Execution time Memory
535634 2022-03-10T17:52:50 Z Rafi22 Olympic Bus (JOI20_ho_t4) C++14
100 / 100
221 ms 5640 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

const int N=207,M=50007;

struct edge
{
    int u,id;
    ll c,d;
};
vector<edge>G[N][2];
int n,m;
bool is[M];
int o[N],k[N];

vector<ll> dijkstra(int p,int ban,int c)
{
    vector<ll>d(n+1,infl);
    vector<bool>odw(n+1,0);
    memset(o,0,sizeof o);
    memset(k,0,sizeof k);
    d[p]=0;
    while(true)
    {
        int v;
        ll mn=infl;
        for(int i=1;i<=n;i++)
        {
            if(!odw[i]&&d[i]<mn)
            {
                v=i;
                mn=d[i];
            }
        }
        if(mn==infl) break;
        odw[v]=1;
        for(auto e:G[v][c])
        {
            if(e.id==ban) continue;
            if(d[v]+e.c<d[e.u])
            {
                d[e.u]=d[v]+e.c;
                o[e.u]=v;
                k[e.u]=e.id;
            }
        }
    }
    return d;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        ll c,d;
        cin>>u>>v>>c>>d;
        G[u][0].pb({v,i,c,d});
        G[v][1].pb({u,i,c,d});
    }
    vector<ll>D1=dijkstra(1,-1,0);
    for(int i=1;i<=n;i++)
    {
        int x=i;
        if(D1[i]==infl) x=0;
        while(x)
        {
            is[k[x]]=1;
            x=o[x];
        }
    }
    vector<ll>D1r=dijkstra(1,-1,1);
    for(int i=1;i<=n;i++)
    {
        int x=i;
        if(D1r[i]==infl) x=0;
        while(x)
        {
            is[k[x]]=1;
            x=o[x];
        }
    }
    vector<ll>Dn=dijkstra(n,-1,0);
    for(int i=1;i<=n;i++)
    {
        int x=i;
        if(Dn[i]==infl) x=0;
        while(x)
        {
            is[k[x]]=1;
            x=o[x];
        }
    }
    vector<ll>Dnr=dijkstra(n,-1,1);
    for(int i=1;i<=n;i++)
    {
        int x=i;
        if(Dnr[i]==infl) x=0;
        while(x)
        {
            is[k[x]]=1;
            x=o[x];
        }
    }
    ll ans=min(infl,D1[n]+Dn[1]);
    for(int v=1;v<=n;v++)
    {
        for(auto e:G[v][0])
        {
            if(is[e.id])
            {
                G[e.u][0].pb({v,-1,e.c,e.d});
                vector<ll>neD1=dijkstra(1,e.id,0);
                vector<ll>neDn=dijkstra(n,e.id,0);
                G[e.u][0].pop_back();
                ans=min(ans,neD1[n]+neDn[1]+e.d);
            }
            else
            {
                ll X=D1[e.u]+Dnr[v]+e.c,Y=Dn[e.u]+D1r[v]+e.c;
                ans=min(ans,X+e.d+min(Dn[1],Y));
                ans=min(ans,Y+e.d+min(X,D1[n]));
            }
        }
    }
    if(ans==infl) cout<<-1;
    else cout<<ans;

    return 0;
}

Compilation message

ho_t4.cpp: In function 'std::vector<long long int> dijkstra(int, int, int)':
ho_t4.cpp:55:23: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |                 o[e.u]=v;
      |                 ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 60 ms 460 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 102 ms 340 KB Output is correct
4 Correct 128 ms 408 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 53 ms 412 KB Output is correct
11 Correct 70 ms 340 KB Output is correct
12 Correct 67 ms 416 KB Output is correct
13 Correct 32 ms 424 KB Output is correct
14 Correct 71 ms 420 KB Output is correct
15 Correct 71 ms 428 KB Output is correct
16 Correct 82 ms 412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 221 ms 4220 KB Output is correct
2 Correct 197 ms 4252 KB Output is correct
3 Correct 194 ms 4368 KB Output is correct
4 Correct 101 ms 492 KB Output is correct
5 Correct 74 ms 412 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 73 ms 4152 KB Output is correct
10 Correct 69 ms 5332 KB Output is correct
11 Correct 133 ms 5180 KB Output is correct
12 Correct 148 ms 5184 KB Output is correct
13 Correct 125 ms 5400 KB Output is correct
14 Correct 116 ms 5640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 416 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
3 Correct 181 ms 3064 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 209 ms 4160 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 79 ms 4184 KB Output is correct
9 Correct 78 ms 5076 KB Output is correct
10 Correct 136 ms 5144 KB Output is correct
11 Correct 152 ms 5176 KB Output is correct
12 Correct 166 ms 5308 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 336 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 149 ms 5280 KB Output is correct
20 Correct 142 ms 5192 KB Output is correct
21 Correct 151 ms 5252 KB Output is correct
22 Correct 163 ms 4924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 460 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 102 ms 340 KB Output is correct
4 Correct 128 ms 408 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 53 ms 412 KB Output is correct
11 Correct 70 ms 340 KB Output is correct
12 Correct 67 ms 416 KB Output is correct
13 Correct 32 ms 424 KB Output is correct
14 Correct 71 ms 420 KB Output is correct
15 Correct 71 ms 428 KB Output is correct
16 Correct 82 ms 412 KB Output is correct
17 Correct 221 ms 4220 KB Output is correct
18 Correct 197 ms 4252 KB Output is correct
19 Correct 194 ms 4368 KB Output is correct
20 Correct 101 ms 492 KB Output is correct
21 Correct 74 ms 412 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 73 ms 4152 KB Output is correct
26 Correct 69 ms 5332 KB Output is correct
27 Correct 133 ms 5180 KB Output is correct
28 Correct 148 ms 5184 KB Output is correct
29 Correct 125 ms 5400 KB Output is correct
30 Correct 116 ms 5640 KB Output is correct
31 Correct 65 ms 416 KB Output is correct
32 Correct 8 ms 340 KB Output is correct
33 Correct 181 ms 3064 KB Output is correct
34 Correct 4 ms 340 KB Output is correct
35 Correct 209 ms 4160 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 79 ms 4184 KB Output is correct
39 Correct 78 ms 5076 KB Output is correct
40 Correct 136 ms 5144 KB Output is correct
41 Correct 152 ms 5176 KB Output is correct
42 Correct 166 ms 5308 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 0 ms 336 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 149 ms 5280 KB Output is correct
50 Correct 142 ms 5192 KB Output is correct
51 Correct 151 ms 5252 KB Output is correct
52 Correct 163 ms 4924 KB Output is correct
53 Correct 187 ms 5064 KB Output is correct
54 Correct 203 ms 4800 KB Output is correct
55 Correct 184 ms 4976 KB Output is correct
56 Correct 118 ms 596 KB Output is correct
57 Correct 114 ms 436 KB Output is correct
58 Correct 105 ms 3912 KB Output is correct
59 Correct 98 ms 3924 KB Output is correct
60 Correct 140 ms 3972 KB Output is correct
61 Correct 85 ms 3796 KB Output is correct
62 Correct 97 ms 3920 KB Output is correct
63 Correct 137 ms 3780 KB Output is correct
64 Correct 139 ms 4256 KB Output is correct
65 Correct 140 ms 4172 KB Output is correct
66 Correct 175 ms 4272 KB Output is correct
67 Correct 15 ms 3528 KB Output is correct
68 Correct 69 ms 5272 KB Output is correct
69 Correct 68 ms 5328 KB Output is correct
70 Correct 139 ms 5100 KB Output is correct
71 Correct 134 ms 5196 KB Output is correct
72 Correct 130 ms 5332 KB Output is correct
73 Correct 156 ms 5480 KB Output is correct
74 Correct 141 ms 5376 KB Output is correct