Submission #988078

# Submission time Handle Problem Language Result Execution time Memory
988078 2024-05-24T04:12:47 Z michified Robot (JOI21_ho_t4) C++17
0 / 100
192 ms 28576 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
struct state_t {
	int id, inc;
	ll cost;
};
 
struct edge_t {
	int to, col;
	ll cost;
};
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
 
	auto cmp = [](const state_t& a, const state_t& b){return a.cost > b.cost;};
	priority_queue<state_t, vector<state_t>, decltype(cmp)> pq(cmp);
	int n, m, i, tu, tv, tw, tc;
	cin >> n >> m;
	vector<vector<edge_t>> adj(n + 1);
	vector<unordered_map<int, ll>> coltot(n + 1);
	vector<unordered_map<int, vector<edge_t>>> c2e(n + 1);
	for (i = 0; i < m; i++) {
		cin >> tu >> tv >> tc >> tw;
		adj[tu].push_back({tv, tc, tw});
		adj[tv].push_back({tu, tc, tw});
		coltot[tu][tc] += tw;
		coltot[tv][tc] += tw;
		c2e[tu][tc].push_back({tv, tc, tw});
		c2e[tv][tc].push_back({tu, tc, tw});
	}
	vector<map<int, ll>> best(n + 1);
	pq.push({1, 0, 0});
	best[1][0] = 0;
	while (not pq.empty()) {
		state_t cur = pq.top();
		pq.pop();
		if (cur.id == n and cur.inc == 0) {
			cout << cur.cost;
			return 0;
		}
		if (cur.cost > best[cur.id][cur.inc]) continue;
		if (cur.inc == 0) {
			for (edge_t& e : adj[cur.id]) {
				ll tmp = cur.cost + coltot[cur.id][e.col] - e.cost;
				if (best[e.to].find(0) == best[e.to].end() or best[e.to][0] > tmp) {
					pq.push({e.to, 0, tmp});
					best[e.to][0] = tmp;
				}
				tmp = cur.cost;
				if (best[e.to].find(e.col) == best[e.to].end() or best[e.to][e.col] > tmp) {
					pq.push({e.to, e.col, tmp});
					best[e.to][e.col] = tmp;
				}
				tmp = cur.cost + e.cost;
				if (best[e.to].find(0) == best[e.to].end() or best[e.to][0] > tmp) {
					pq.push({e.to, e.col, tmp});
					best[e.to][0] = tmp;
				}
			}
		} else {
			for (edge_t& e : c2e[cur.id][cur.inc]) {
				ll tmp = cur.cost + coltot[cur.id][e.col] - e.cost;
				if (best[e.to].find(0) == best[e.to].end() or best[e.to][0] > tmp) {
					pq.push({e.to, 0, tmp});
					best[e.to][0] = tmp;
				}
			}
		}
	}
	cout << -1;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 192 ms 28576 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -