Submission #424342

# Submission time Handle Problem Language Result Execution time Memory
424342 2021-06-11T19:53:06 Z Harry464 Robot (JOI21_ho_t4) C++14
0 / 100
404 ms 52132 KB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

vector <vector<pair <ll, pair<ll,ll> > > > adjl(1000000);

int main()
{

    ll n, m;
    cin >> n >> m;

    for (int i = 0; i < m; i++){

        ll u, v, c, p;
        cin >> u >> v >> c >> p;
        pair <ll,ll> drugi = make_pair(c,p);
        u--, v--;

        adjl[u].push_back(make_pair(v, drugi)), adjl[v].push_back(make_pair(u, drugi));

    }

    vector <ll> tmp(2,1000000000000000000);
    vector <ll> cols(m + 1, 0);
    vector <vector <ll> > mini(n, tmp);
    mini[0][0] = 0, mini[0][1] = 0;

    priority_queue <pair <ll, pair<ll,pair<ll,ll> > > > dijk;
    dijk.push(make_pair(0, make_pair(0, make_pair(-1,-1))));

    while (dijk.size()){

        ll pric = -dijk.top().first, u = dijk.top().second.first, ori = dijk.top().second.second.first, col = dijk.top().second.second.first;

        dijk.pop();

        if (col == 0 && pric > mini[u][1])
            continue;
        else if (col != 0 && pric > mini[u][0])
            continue;

        for (int i = 0; i < adjl[u].size(); i++){

            ll v = adjl[u][i].first, c = adjl[u][i].second.first, p = adjl[u][i].second.second;
            if (v != ori || col != 0)
             cols[c] += p;

        }

        for (int i = 0; i < adjl[u].size(); i++){

            ll v = adjl[u][i].first, c = adjl[u][i].second.first, p = adjl[u][i].second.second;

            if (cols[c] - p == 0 && mini[v][0] > pric)
                mini[v][0] = pric, dijk.push(make_pair(-pric, make_pair(v, make_pair(u,c))));

            if (cols[c] - p > 0){

                ll most = cols[c] - p;

                if (most + pric < mini[v][0])
                    mini[v][0] = pric + most, dijk.push(make_pair(-pric-most, make_pair(v, make_pair(u,c))));

                if (p + pric < mini[v][1])
                    mini[v][1] = pric + p, dijk.push(make_pair(-pric-p, make_pair(v, make_pair(u,0))));

            }

            if (p + pric < mini[v][1])
                mini[v][1] = pric + p, dijk.push(make_pair(-pric-p, make_pair(v, make_pair(u,0))));

        }
        for (int i = 0; i < adjl[u].size(); i++){

            ll v = adjl[u][i].first, c = adjl[u][i].second.first, p = adjl[u][i].second.second;
            if (v != ori || col != 0)
             cols[c] -= p;

        }

    }

    if (min(mini[n-1][0], mini[n-1][1]) == 1000000000000000000)
        cout << "-1";
    else
        cout << min(mini[n-1][0], mini[n-1][1]);

}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:48:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for (int i = 0; i < adjl[u].size(); i++){
      |                         ~~^~~~~~~~~~~~~~~~
Main.cpp:56:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for (int i = 0; i < adjl[u].size(); i++){
      |                         ~~^~~~~~~~~~~~~~~~
Main.cpp:79:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for (int i = 0; i < adjl[u].size(); i++){
      |                         ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 16 ms 23680 KB Output is correct
3 Correct 15 ms 23756 KB Output is correct
4 Correct 16 ms 23700 KB Output is correct
5 Correct 16 ms 23776 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 17 ms 23848 KB Output is correct
8 Correct 16 ms 23844 KB Output is correct
9 Incorrect 18 ms 24012 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 158 ms 33288 KB Output is correct
2 Correct 73 ms 28344 KB Output is correct
3 Correct 232 ms 37968 KB Output is correct
4 Correct 109 ms 30096 KB Output is correct
5 Incorrect 404 ms 52132 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 23756 KB Output is correct
2 Correct 16 ms 23680 KB Output is correct
3 Correct 15 ms 23756 KB Output is correct
4 Correct 16 ms 23700 KB Output is correct
5 Correct 16 ms 23776 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 17 ms 23848 KB Output is correct
8 Correct 16 ms 23844 KB Output is correct
9 Incorrect 18 ms 24012 KB Output isn't correct
10 Halted 0 ms 0 KB -