Submission #1109087

#TimeUsernameProblemLanguageResultExecution timeMemory
1109087InvMODRobot (JOI21_ho_t4)C++14
0 / 100
94 ms23432 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define gcd __gcd
#define sz(v) (int) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define dbg(x) "[" #x " = " << (x) << "]"
#define int long long

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;}

const int N = 2e5+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;

struct Edge{
    int v,color,cost;
    Edge(int v = 0, int color = 0, int cost = 0): v(v), color(color), cost(cost) {}
};

int n, m, color_cost[N];

int dist[N];

vector<Edge> adj[N];

void solve()
{
    cin >> n >> m;

    FOR(i, 1, m){
        int u,v,c,w;
        cin >> u >> v >> c >> w;
        adj[u].push_back(Edge(v, c, w));
        adj[v].push_back(Edge(u, c, w));
    }

    FOR(i, 1, n){
        for(Edge& e : adj[i]){
            int color = e.color, cost = e.cost;
            color_cost[color] += cost;
        }

        for(Edge& e : adj[i]){
            int color = e.color;
            e.cost = (color_cost[color] - e.cost != 0 ? e.cost : 0);
        }

        for(Edge& e : adj[i]){
            int color = e.color;
            color_cost[color] = 0;
        }
    }

    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;

    FOR(i, 2, n) dist[i] = INF;
    pq.push(make_pair(0, 1));

    while(!pq.empty()){
        pair<int,int> e = pq.top(); pq.pop();

        int x = e.second, cur_dist = e.first;

        if(cur_dist > dist[x]) continue;

        for(Edge& eq : adj[x]){
            int v = eq.v, cost = eq.cost;

            if(ckmn(dist[v], dist[x] + cost)){
                pq.push(make_pair(dist[v], v));
            }
        }
    }

    cout << (dist[n] != INF ? dist[n] : -1) <<"\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP","r",stdin);
        freopen(name".OUT","w",stdout);
    }

    int t = 1; //cin >> t;
    while(t--) solve();
    return 0;
}

Compilation message (stderr)

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