Submission #446837

#TimeUsernameProblemLanguageResultExecution timeMemory
446837gsc2001Robot (JOI21_ho_t4)C++17
0 / 100
450 ms41984 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define f(i, l, r) for (int i = l; i <= r; i++) #define debug(x) cout << #x << '=' << (x) << endl #define pb push_back #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define ff first #define ss second using PLL = pair<ll, ll>; using VL = vector<ll>; using VLL = vector<pair<ll, ll>>; // ------------------------------------------------------------------------------- constexpr int mod = 1e9 + 7; void setIO(const string &name = "") { ios_base::sync_with_stdio(0); cin.tie(0); if (sz(name)) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } // ------------------------------------------------------------------------------- // ------------------------Template End ------------------------------------------ // ------------------------------------------------------------------------------- struct Edge { ll color, changePrice, to; Edge(ll t, ll c, ll p) : color(c), changePrice(p), to(t) { } }; int main() { setIO(); ll n, m; cin >> n >> m; vector<vector<Edge>> adj(n); vector<map<ll, ll>> colorCount(n); ll a, b, c, p; for (int i = 0; i < m; i++) { cin >> a >> b >> c >> p; a--, b--; adj[a].push_back(Edge(b, c, p)); adj[b].push_back(Edge(a, c, p)); colorCount[a][c]++; colorCount[b][c]++; } priority_queue<pair<ll, ll>> pq; vector<ll> dist(n, 1e18); dist[0] = 0; pq.push({0, 0}); ll distNow, node; while (!pq.empty()) { tie(distNow, node) = pq.top(); distNow = -distNow; pq.pop(); if (dist[node] != distNow) continue; for (auto edge: adj[node]) { ll len = 0; if (colorCount[node][edge.color] > 1) { len += edge.changePrice; } if (dist[node] + len < dist[edge.to]) { dist[edge.to] = dist[node] + len; pq.push({-dist[edge.to], edge.to}); } } } if (dist[n - 1] == 1e18) { cout << "-1"; } else cout << dist[n - 1]; return 0; }

Compilation message (stderr)

Main.cpp: In function 'void setIO(const string&)':
Main.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...