Submission #941867

#TimeUsernameProblemLanguageResultExecution timeMemory
941867May27_thRobot (JOI21_ho_t4)C++17
0 / 100
3099 ms1077652 KiB
#include<bits/stdc++.h> #define taskname "A" using namespace std; void World_Final(); void Solve(); int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); if (fopen(taskname".in", "r")) { freopen(taskname".in", "r", stdin); freopen(taskname".out", "w", stdout); } World_Final(); } void World_Final(){ int Tests = 1; //cin >> Tests; for (int i = 1; i <= Tests; i ++) { //cout << i << "\n"; Solve(); } } const int MAXN = 2e5 + 10; const int64_t INF = 1e18; int N, M; struct Road { int v, c; int64_t p; Road (int _v, int _c, int64_t _p) : v(_v), c(_c), p(_p) {}; }; vector<Road> G[MAXN]; pair<int, int64_t> par[MAXN]; int64_t f[MAXN]; map<int, int64_t> color[MAXN], sum[MAXN]; void Solve(){ cin >> N >> M; for (int i = 1; i <= M; i ++) { int u, v, c; int64_t p; cin >> u >> v >> c >> p; G[u].push_back(Road(v, c, p)); G[v].push_back(Road(u, c, p)); sum[u][c] += p; sum[v][c] += p; color[u][c] ++; color[v][c] ++; } for (int i = 1; i <= N; i ++) { f[i] = INF; par[i] = make_pair(0, 0); } f[1] = 0; priority_queue<pair<int64_t, int>> pq; pq.push(make_pair(0, 1)); while (!pq.empty()) { int64_t d; int u; tie(d, u) = pq.top(); pq.pop(); if (-d != f[u]) continue; for (auto [v, c, p] : G[u]) { int cnt = color[u][c] - (par[u].first == c); int64_t w = sum[u][c] - p - (par[u].first == c ? par[u].second : 0); if (w > p) w = p; if (cnt <= 1) w = 0; if (f[v] > f[u] + w) { f[v] = f[u] + w; pq.push(make_pair(-f[v], v)); if(w != 0) par[v] = make_pair(c, p); } } } cout << (f[N] == INF ? -1 : f[N]); }

Compilation message (stderr)

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