Submission #580302

#TimeUsernameProblemLanguageResultExecution timeMemory
580302GusterGoose27Robot (JOI21_ho_t4)C++11
0 / 100
230 ms25000 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;
}

void adj_edges(int i) {
	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);
	}
}

void dijkstra() {
	dist[0] = 0;
	set<pii> pq;
	pq.insert(pii(0, 0));
	while (!pq.empty()) {
		pii cur = *(pq.begin());
		pq.erase(cur);
		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)
				edges[cur.second][i].cost += dist[edges[cur.second][i].node]-cur.first;
		}
		adj_edges(cur.second);
		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)':
Main.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for (int j = 0; j < edges[i].size(); ) {
      |                  ~~^~~~~~~~~~~~~~~~~
Main.cpp:43:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   while (j < edges[i].size() && edges[i][orig].color == edges[i][j].color) {
      |          ~~^~~~~~~~~~~~~~~~~
Main.cpp: In function 'void dijkstra()':
Main.cpp:59:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   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...