Submission #417548

# Submission time Handle Problem Language Result Execution time Memory
417548 2021-06-03T23:03:32 Z APROHACK Robot (JOI21_ho_t4) C++14
0 / 100
168 ms 20332 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define ll long long
// Mira las constantes
// Estudia las propiedades
// Keep calm
ll n, m;
vector<pair<pair<int, ll>, int> >g[100001];
ll dijkstra(){
    priority_queue<pair<ll, int> >pq;
    pq.push({0, 1});
    ll u, v,ci;
    ll D[100001];
    for(int i = 0 ; i <= 100000 ; i++)D[i]=LLONG_MAX;
    D[1]=0;
    while(pq.size()){
        u=pq.top().S;
        ci=(pq.top().F)*-1;
        pq.pop();
        bool isval=true;
        for(int i = 0 ; i < g[u].size() ; i++){
            isval=true;
            if(i>0&&g[u][i-1].F.F==g[u][i].F.F)isval=false;
            if(i+1<g[u].size()&&g[u][i+1].F.F==g[u][i].F.F)isval=false;
            if(isval){
                if(D[g[u][i].S]>ci){
                    D[g[u][i].S]=ci;
                    pq.push({-1*(ci), g[u][i].S});
                }else{
                    continue;
                }
            }else{
                if(D[g[u][i].S]>ci+g[u][i].F.S){
                    D[g[u][i].S]=ci+g[u][i].F.S;
                    pq.push({-1*(ci+g[u][i].F.S), g[u][i].S});
                }else{
                    continue;
                }
            }
        }
    }
    return D[n];
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    
    cin>>n>>m;
    ll a, b, c, p;
    for(int i = 0 ; i < m ; i++){
        cin>>a>>b>>c>>p;
        g[a].PB({{c, p}, b});
        g[b].PB({{c, p}, a});
    }
    for(int i = 1 ; i <= n; i++){
        sort(g[i].begin(), g[i].end());
    }
    ll res=dijkstra();
    if(res==LLONG_MAX){
        cout<<"-1\n";
    }else{
        cout<<res;  
    }
}

Compilation message

Main.cpp: In function 'long long int dijkstra()':
Main.cpp:24:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, long long int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for(int i = 0 ; i < g[u].size() ; i++){
      |                         ~~^~~~~~~~~~~~~
Main.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, long long int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             if(i+1<g[u].size()&&g[u][i+1].F.F==g[u][i].F.F)isval=false;
      |                ~~~^~~~~~~~~~~~
Main.cpp:15:11: warning: unused variable 'v' [-Wunused-variable]
   15 |     ll u, v,ci;
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3436 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Incorrect 3 ms 3532 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 79 ms 9788 KB Output is correct
2 Correct 26 ms 6144 KB Output is correct
3 Correct 89 ms 16872 KB Output is correct
4 Correct 42 ms 8496 KB Output is correct
5 Incorrect 168 ms 20332 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Correct 2 ms 3404 KB Output is correct
3 Correct 2 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3436 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Incorrect 3 ms 3532 KB Output isn't correct
8 Halted 0 ms 0 KB -