답안 #147851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147851 2019-08-31T02:19:10 Z luciocf Ceste (COCI17_ceste) C++14
160 / 160
675 ms 25368 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

const int maxn = 2e3+10;
const int maxv = 1e6+10;
const ll inf = 1e18+10;

int n;

int last[maxn];

ll ans[maxn];

vector<pair<pii, int>> grafo[maxn];

void dijkstra(void)
{
	for (int i = 1; i < maxn; i++)
		ans[i] = inf, last[i] = maxv;

	priority_queue<pair<pii, int>, vector<pair<pii, int>>, greater<pair<pii, int>>> fila;

	fila.push({{0, 0}, 1}), ans[1] = 0, last[1] = 0;

	while (!fila.empty())
	{
		int u = fila.top().second;
		int sum_c = fila.top().first.first, sum_t = fila.top().first.second;
		fila.pop();

		if (last[u] < sum_t) continue;

		last[u] = sum_t;
		ans[u] = min(ans[u], 1ll*sum_t*sum_c);

		for (auto pp: grafo[u])
		{
			int v = pp.second;
			int t = pp.first.second, c = pp.first.first;

			if (sum_t+t > maxv || sum_c+c > maxv) continue;

			fila.push({{sum_c+c, sum_t+t}, v});
		}
	}
}

int main(void)
{
	int m;
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= m; i++)
	{
		int u, v, t, c;
		scanf("%d %d %d %d", &u, &v, &t, &c);

		grafo[u].push_back({{c, t}, v});
		grafo[v].push_back({{c, t}, u});
	}

	dijkstra();

	for (int i = 2; i <= n; i++)
	{
		if (ans[i] == inf) printf("-1\n");
		else printf("%lld\n", ans[i]);
	}
}

Compilation message

ceste.cpp: In function 'int main()':
ceste.cpp:55: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:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d %d", &u, &v, &t, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 6 ms 764 KB Output is correct
3 Correct 7 ms 824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 2164 KB Output is correct
2 Correct 69 ms 3816 KB Output is correct
3 Correct 84 ms 3816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 221 ms 3776 KB Output is correct
2 Correct 675 ms 25368 KB Output is correct
3 Correct 9 ms 952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 1476 KB Output is correct
2 Correct 390 ms 13116 KB Output is correct
3 Correct 16 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 286 ms 1560 KB Output is correct
2 Correct 285 ms 3816 KB Output is correct
3 Correct 252 ms 3864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 3836 KB Output is correct
2 Correct 237 ms 3816 KB Output is correct
3 Correct 353 ms 3820 KB Output is correct