Submission #580304

#TimeUsernameProblemLanguageResultExecution timeMemory
580304GusterGoose27Robot (JOI21_ho_t4)C++11
100 / 100
248 ms24948 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; class Edge { public: int node; ll weight; int color; int cost; Edge(int n, int c, int co) { node = n; weight = 0; color = c; cost = co; } }; bool operator<(const Edge &a, const Edge &b) { return a.color < b.color; } typedef pair<ll, int> pii; const int MAXN = 1e5; const int MAXM = 2e5; int n, m; vector<Edge> edges[MAXN]; ll dist[MAXN]; ll min(ll a, ll b) { if (a < b) return a; return b; } ll get(unordered_map<int, ll> &red, int k) { if (red.find(k) == red.end()) return 0; return red[k]; } void adj_edges(int i, unordered_map<int, ll> &red) { sort(edges[i].begin(), edges[i].end()); for (int j = 0; j < edges[i].size(); ) { int orig = j; ll osum = 0; while (j < edges[i].size() && edges[i][orig].color == edges[i][j].color) { osum += edges[i][j].cost; j++; } if (j == orig+1) continue; else for (int k = orig; k < j; k++) edges[i][k].weight = min(edges[i][k].cost, osum-edges[i][k].cost-get(red, edges[i][k].color)); } } void dijkstra() { dist[0] = 0; set<pii> pq; pq.insert(pii(0, 0)); while (!pq.empty()) { pii cur = *(pq.begin()); pq.erase(cur); unordered_map<int, ll> red; for (int i = 0; i < edges[cur.second].size(); i++) { if (dist[edges[cur.second][i].node] >= 0 && dist[edges[cur.second][i].node] < cur.first) { int curc = edges[cur.second][i].color; int curred = cur.first-dist[edges[cur.second][i].node]; if (red.find(curc) == red.end() || curred > red[curc]) red[curc] = curred; } } adj_edges(cur.second, red); for (Edge e: edges[cur.second]) { int next = e.node; if (dist[next] == -1 || dist[cur.second]+e.weight < dist[next]) { pq.erase(pii(dist[next], next)); dist[next] = dist[cur.second]+e.weight; pq.insert(pii(dist[next], next)); } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < m; i++) { int x, y, c, co; cin >> x >> y >> c >> co; x--; y--; c--; edges[x].push_back(Edge(y, c, co)); edges[y].push_back(Edge(x, c, co)); } //for (int i = 0; i < n; i++) adj_edges(i); fill(dist, dist+n, -1); dijkstra(); cout << dist[n-1] << "\n"; }

Compilation message (stderr)

Main.cpp: In function 'void adj_edges(int, std::unordered_map<int, long long int>&)':
Main.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for (int j = 0; j < edges[i].size(); ) {
      |                  ~~^~~~~~~~~~~~~~~~~
Main.cpp:48:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   while (j < edges[i].size() && edges[i][orig].color == edges[i][j].color) {
      |          ~~^~~~~~~~~~~~~~~~~
Main.cpp: In function 'void dijkstra()':
Main.cpp:65:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for (int i = 0; i < edges[cur.second].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...