Submission #1093056

# Submission time Handle Problem Language Result Execution time Memory
1093056 2024-09-25T18:56:26 Z Dennis_Jason Olympic Bus (JOI20_ho_t4) C++14
0 / 100
165 ms 140120 KB
#include <bits/stdc++.h>
#define NMAX 1000001
#define pb push_back
#define eb emplace_back
#define MOD 100003
#define nl '\n'
#define INF 1e18
#define LLONG_MAX 9223372036854775807
#define pii pair<int,int>
#define tpl tuple<int,int,int>
//#pragma GCC optimize("O3")
#define int long long
//#define cin fin
//#define cout fout
using namespace std;
ifstream fin("feast.in");
ofstream fout("feast.out");
/*
 *
    ================DEMONSTRATION===================



    =====================END========================
 */
int n,m;
vector<vector<tpl>>G(NMAX);
vector<vector<int>>dist_from_one(NMAX,vector<int>(2,INF));
vector<vector<int>>dist_from_n(NMAX,vector<int>(2,INF));
void dijkstra(int node,vector<vector<int>>&dist)
{
    priority_queue<tpl,vector<tpl>,greater<tpl>>pq;
    dist[node][0]=0;
    pq.push({dist[node][0],node,0});
    bool use[NMAX][2];
    memset(use,false,sizeof(use));
    while(!pq.empty())
    {
        auto[dis,first,inverted]=pq.top();
        pq.pop();
        if(use[first][inverted])
            continue;
        use[first][inverted]=1;
        for(auto [x,cost,inv]:G[first])
        {
            if(inverted && inv)
                continue;
            if(!inverted && inv)
            {
                if(dist[x][1]>dist[first][inverted]+cost)
                {
                    dist[x][1]=dist[first][inverted]+cost;
                    pq.push({dist[x][1],x,1});
                }

            }
            else if(!inv)
            {
                if(dist[x][inverted]>dist[first][inverted]+cost)
                {
                     dist[x][inverted]=dist[first][inverted]+cost;
                     pq.push({dist[x][inverted],x,inverted});
                }
            }
        }
    }
}
signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;
    for(int i=1;i<=m;++i)
    {
        int x,y,c,d;
        cin>>x>>y>>c>>d;
        G[x].pb({y,c,0});
        G[y].pb({x,c+d,1});
    }

    dijkstra(1,dist_from_one);
    dijkstra(n,dist_from_n);
    int mini=min(dist_from_n[1][0]+dist_from_one[n][1],dist_from_n[1][1]+dist_from_one[n][0]);
    mini=min(mini,dist_from_n[1][0]+dist_from_one[n][0]);
    if(mini>=INF)
        cout<<-1;
    else
        cout<<mini;

    return 0;
}

Compilation message

ho_t4.cpp:8: warning: "LLONG_MAX" redefined
    8 | #define LLONG_MAX 9223372036854775807
      | 
In file included from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:195,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:34,
                 from /usr/include/c++/10/climits:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:39,
                 from ho_t4.cpp:1:
/usr/include/limits.h:135: note: this is the location of the previous definition
  135 | #  define LLONG_MAX __LONG_LONG_MAX__
      | 
ho_t4.cpp: In function 'void dijkstra(long long int, std::vector<std::vector<long long int> >&)':
ho_t4.cpp:39:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   39 |         auto[dis,first,inverted]=pq.top();
      |             ^
ho_t4.cpp:44:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |         for(auto [x,cost,inv]:G[first])
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 97 ms 135760 KB Output is correct
2 Correct 92 ms 135252 KB Output is correct
3 Correct 90 ms 135540 KB Output is correct
4 Correct 92 ms 135508 KB Output is correct
5 Correct 109 ms 135504 KB Output is correct
6 Correct 90 ms 135504 KB Output is correct
7 Incorrect 91 ms 135252 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 125 ms 140112 KB Output is correct
2 Correct 125 ms 139856 KB Output is correct
3 Correct 141 ms 140112 KB Output is correct
4 Correct 92 ms 135500 KB Output is correct
5 Correct 91 ms 135508 KB Output is correct
6 Correct 91 ms 135504 KB Output is correct
7 Correct 98 ms 135508 KB Output is correct
8 Correct 91 ms 135252 KB Output is correct
9 Incorrect 165 ms 140120 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 101 ms 135504 KB Output is correct
2 Correct 105 ms 135508 KB Output is correct
3 Correct 138 ms 138948 KB Output is correct
4 Correct 103 ms 135504 KB Output is correct
5 Correct 142 ms 139856 KB Output is correct
6 Incorrect 104 ms 135248 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 97 ms 135760 KB Output is correct
2 Correct 92 ms 135252 KB Output is correct
3 Correct 90 ms 135540 KB Output is correct
4 Correct 92 ms 135508 KB Output is correct
5 Correct 109 ms 135504 KB Output is correct
6 Correct 90 ms 135504 KB Output is correct
7 Incorrect 91 ms 135252 KB Output isn't correct
8 Halted 0 ms 0 KB -