Submission #1036033

#TimeUsernameProblemLanguageResultExecution timeMemory
1036033tradzRobot (JOI21_ho_t4)C++14
0 / 100
117 ms39412 KiB
#include <bits/stdc++.h>

#define For(i,a,b) for(int i = a; i <= b; i++)
#define Ford(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define ii pair<ll,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define RRH(v) v.resize(unique(all(v)) - v.begin())

using namespace std;
const int  N = 1e6+7;
const int M = 1e9+7;
const ll oo = 3e18;

int n, m;
struct data {
    int v, c, p;
};

vector<data> g[N];

ll d[N];

void dij() {
    priority_queue<ii, vector<ii>, greater<ii>> q;

    q.push({0, 1});
    while(q.size()) {
        auto k = q.top();
        q.pop();
        if (d[k.se] != k.fi) continue;
        unordered_map<int,int> ma;
        for (auto x: g[k.se]) ma[x.c]++;
        for (auto x: g[k.se]) {
            if (ma[x.c] >= 2) {
                if (d[x.v] > k.fi + x.p) {
                    d[x.v] = k.fi + x.p;
                    q.push({d[x.v], x.v});
                }
            }
            else {
                if (d[x.v] > k.fi) {
                    d[x.v] = k.fi;
                    q.push({d[x.v], x.v});
                }
            }
        }
    }

    if (d[n] >= oo) d[n] = -1;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    #define TASK ""
    if (fopen (".inp", "r")) {
        freopen (".inp", "r", stdin);
        freopen (".out", "w", stdout);
    }
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }

    cin >> n >> m;
    For (i, 1, m) {
        int u, v, c, p;
        cin >> u >> v >> c >> p;
        g[u].push_back({v, c, p});
        g[v].push_back({u, c, p});
    }

    For (i, 1, n) d[i] = oo;
    d[1] = 0;
    dij();

    cout << d[n] << '\n';

    return 0;
}


Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:60:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen (".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:61:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen (".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...