Submission #1198914

#TimeUsernameProblemLanguageResultExecution timeMemory
1198914hoa208Robot (JOI21_ho_t4)C++20
100 / 100
522 ms97016 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const   ll mod = 1e9 + 7;
const   ll INF = 1e18;
inline  void adm(ll &x){if(x>=mod)x%=mod;else if(x<0)x+=mod;}
//--------------------------------------------------------------------
const ll N = 1e5 + 10;
ll n, m;
unordered_map<ll, vector<pa>> g[N];
ll d[N];
unordered_map<ll, ll> d2[N], clr[N];
void DJK() {
    priority_queue<pair<ll, pa>> q;
    memset(d, 0x3f, sizeof d);
    d[1] = 0;
    q.push({0, {1, 0}});
    while(!q.empty()) {
        ll u = q.top().se.fi,  cost = -q.top().fi, c = q.top().se.se;
        q.pop();
        if(c != 0) {
            if(d2[u][c] != cost) continue;
            for(auto e : g[u][c]) {
                ll v = e.fi, _c = c, p = e.se;
                ll val = cost + clr[u][_c] - p;
                if(d[v] > val) {
                    d[v] = val;
                    q.push({-d[v],{v, 0}});
                }
            }
        }
        else {
            if(cost != d[u]) continue;
            if(u == n) {
                cout << cost;
                exit(0);
            }
            for(auto cs : g[u]) {
                ll _c = cs.fi;
                for(auto e : cs.se) {
                    ll v = e.fi, p = e.se;
                    ll val = cost + clr[u][_c] - p;
                    if(d[v] > val) {
                        d[v] = val;
                        q.push({-d[v], {v, 0}});
                    }
                    val = cost + p;
                    if(d[v] > val) {
                        d[v] = val;
                        q.push({-d[v], {v, 0}});
                    }
                    val = cost;
                    if(!d2[v].count(_c) || d2[v][_c] > val) {
                        d2[v][_c] = val;
                        q.push({-d2[v][_c], {v, _c}});
                    }
                }
            }
        }
    }
}
void hbmt() {
    cin >> n >> m;
    FOR(i, 1, m) {
        ll u, v, c, p;
        cin >> u >> v >> c >> p;
        g[u][c].push_back({v, p});
        g[v][c].push_back({u, p});
        clr[u][c] += p;
        clr[v][c] += p;
    }
    DJK();
    cout << -1;
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    
    if(fopen("hbmt.inp", "r")) {
        freopen("hbmt.inp", "r", stdin);
        freopen("hbmt.out", "w", stdout);
    }
    
    // t_test 
    hbmt();
    return 0;
}

Compilation message (stderr)

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