Submission #217491

# Submission time Handle Problem Language Result Execution time Memory
217491 2020-03-30T02:43:45 Z Fischer Ceste (COCI17_ceste) C++14
160 / 160
511 ms 13020 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define re(x, y, z) for (int x=y; x<z; ++x)
#define trav(v, x) for (auto v : x)
using namespace std;
using vi = vector<int>;
using ll = long long;
using vll = vector<ll>;
using iii = pair<pair<int, int>, int>;
const int maxn = 2e3 + 10;
struct Node {
	int to, t, c;
	Node() {}
	Node(int to, int t, int c):
		to(to), t(t), c(c) {}
};
vector<Node> g[maxn];
int n, m;

vll dikjstra(int s) {
	priority_queue<iii, vector<iii>, greater<iii>> Q;
	vll res(n+1, LLONG_MAX);
	vi tim(n+1, INT_MAX);
	Q.push({{0, 0}, s});
	while (!Q.empty()) {
		auto q = Q.top(); Q.pop();
		int v = q.second;
		int t = q.first.second, c = q.first.first;
		res[v] = min(res[v], t*1ll*c);
		if (tim[v] < t) continue;
		else tim[v] = t;
		trav(e, g[v]) {
			Q.push({{c+e.c, t+e.t}, e.to});
		}
	}
	for (int i = 1; i <= n; ++i) {
		if (res[i] == LLONG_MAX) res[i] = -1;
	}
	return res;
} 

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int a, b, t, c;
		scanf("%d%d%d%d", &a, &b, &t, &c);
		g[a].eb(b, t, c);
		g[b].eb(a, t, c);
	}
	vll res = dikjstra(1);
	for (int i = 2; i <= n; ++i) {
		printf("%lld\n", res[i]);
	}
	return 0;
}

Compilation message

ceste.cpp: In function 'int main()':
ceste.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
ceste.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d%d", &a, &b, &t, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 8 ms 512 KB Output is correct
3 Correct 10 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1276 KB Output is correct
2 Correct 59 ms 2040 KB Output is correct
3 Correct 73 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 202 ms 2160 KB Output is correct
2 Correct 511 ms 13020 KB Output is correct
3 Correct 11 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 960 KB Output is correct
2 Correct 311 ms 6756 KB Output is correct
3 Correct 17 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 258 ms 952 KB Output is correct
2 Correct 247 ms 2292 KB Output is correct
3 Correct 213 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 223 ms 2160 KB Output is correct
2 Correct 207 ms 2428 KB Output is correct
3 Correct 288 ms 2156 KB Output is correct