Submission #529601

#TimeUsernameProblemLanguageResultExecution timeMemory
529601abc864197532Robot (JOI21_ho_t4)C++17
34 / 100
759 ms111884 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair<int,int> #define X first #define Y second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T i, U ...j) { cout << i << ' ', abc(j...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } #ifdef Doludu #define test(x...) abc("[" + string(#x) + "]", x) #define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #else #define test(x...) void(0) #define owo ios::sync_with_stdio(false), cin.tie(0) #endif const int N = 200087; vector <pair <int, lli>> adj[N]; map <pii, int> col_to_idx; map <pii, lli> col_sum; int _id = 0; int get(int v, int c) { if (col_to_idx.count({v, c})) return col_to_idx[{v, c}]; return col_to_idx[{v, c}] = _id++; } int main () { owo; int n, m; cin >> n >> m; vector <array <int, 4>> E; for (int i = 0, u, v, c, p; i < m; ++i) { cin >> u >> v >> c >> p, --u, --v, --c; col_sum[{u, c}] += p; col_sum[{v, c}] += p; E.pb({u, v, c, p}); E.pb({v, u, c, p}); } for (auto e : E) { int u = e[0], v = e[1], col = e[2], p = e[3]; int a = get(u, col), b = get(u, -1), c = get(v, col), d = get(v, -1); // only add u -> v adj[a].eb(d, col_sum[{u, col}] - p); adj[b].eb(c, 0); adj[b].eb(d, min(1ll * p, col_sum[{u, col}] - p)); } int st = get(0, -1); vector <lli> dis(_id, 1ll << 60); dis[st] = 0; priority_queue <pair <lli, int>, vector <pair <lli, int>>, greater <pair <lli, int>>> pq; pq.emplace(dis[st], st); while (!pq.empty()) { lli d; int v; tie(d, v) = pq.top(); pq.pop(); for (auto [u, w] : adj[v]) if (dis[u] > dis[v] + w) { dis[u] = dis[v] + w; pq.emplace(dis[u], u); } } lli ans; if (get(n - 1, -1) == dis.size()) ans = -1; else ans = dis[get(n - 1, -1)]; if (ans == 1ll << 60) ans = -1; cout << ans << endl; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:72:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |  if (get(n - 1, -1) == dis.size())
      |      ~~~~~~~~~~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...