Submission #388321

# Submission time Handle Problem Language Result Execution time Memory
388321 2021-04-10T22:41:05 Z Kepha Robot (JOI21_ho_t4) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f3f3f3f3f
#define MX 100000
#define ll long long
using namespace std;

struct Edge {
    int color, next;
    ll price;

    Edge (int _color = 0, int _next = 0, ll _price = 0) {
        color = _color, next = _next, price = _price;
    }
};

int N, M;
map<int, vector<Edge>> adj[MX + 1];
ll dist1[MX + 1];
map<int, ll> dist2[MX + 1], sum[MX + 1];

int main() {;
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		int a, b, c;
		ll d;
		cin >> a >> b >> c >> d;
		adj[a][c].push_back(Edge(c, b, d));
		adj[b][c].push_back(Edge(c, a, d));
		sum[a][c] += d;
		sum[b][c] += d;
	}

	fill(dist1 + 1, dist1 + 1 + N, INF);
	dist1[1] = 0;
	priority_queue<tuple<ll, int, int>> q;
	q.push({0, 1, 0});

	while (q.size()) {
		ll cost;
		int node, color;
		tie(cost, node, c) = q.top();
		q.pop();

		if (color) {
			if (dist2[node][color] != -cost) continue;
			for (Edge edge : adj[node][color]) {
				// We can't flip i in this case
				ll case1 = sum[node][color] - edge.price;
				if (case1 - cost < dist1[edge.next]) {
					dist1[edge.next] = case1 - cost;
					q.push({-dist1[edge.next], edge.next, 0});
				}
			}
		}
		else {
			if (dist1[node] != -cost) continue;
			for (auto& c : adj[node]) {
				for (Edge edge : c.second) {
					// Case 1: We don't flip j
					ll case1 = sum[node][edge.color] - edge.price - cost;
					if (case1 < dist1[edge.next]) {
						dist1[edge.next] = case1;
						q.push({-dist1[edge.next], edge.next, 0});
					}
					// Case 2: We flip j but not another edge of the same colour
					ll case2 = edge.price - cost;
					if (case2 < dist1[edge.next]) {
						dist1[edge.next] = case2;
						q.push({-dist1[edge.next], edge.next, 0});
					}
					// Case 3: We flip j and another edge of the same colour
					ll case3 = -cost;
					if (!dist2[edge.next].count(edge.color) || case3 < dist2[edge.next][edge.color]) {
						dist2[edge.next][edge.color] = case3;
						q.push({-dist2[edge.next][edge.color], edge.next, edge.color});
					}
				}
			}
		}
	}

	if (dist1[N] >= INF) cout << "-1\n";
	else cout << dist1[N] << "\n";

	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:41:19: error: 'c' was not declared in this scope
   41 |   tie(cost, node, c) = q.top();
      |                   ^