답안 #125420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
125420 2019-07-05T09:36:32 Z abacaba Ceste (COCI17_ceste) C++14
16 / 160
2500 ms 131076 KB
#include <bits/stdc++.h>
using namespace std;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
struct edge {
	int to, t, cost;
	edge(int to, int t, int cost) : to(to), t(t), cost(cost) {}
	bool operator < (const edge &b) const {
		if(to == b.to) {
			if(t == b.t)
				return cost < b.cost;
			return t < b.t;
		}
		return to < b.to;
	}
};

struct point {
	int u, v, t, cost;
	point(int u, int v, int t, int cost) : u(u), v(v), t(t), cost(cost) {}
};

const ll inf = 2e15;
const int N = 2e3 + 15;
int n, m;
map <int, int> d[N];
set <edge> g[N];
vector <point> edges;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i = 1; i <= m; ++i) {
		int u, v, t, c;
		cin >> u >> v >> t >> c;
		edges.pb(*new point(u, v, t, c));
		edges.pb(*new point(v, u, t, c));
	}
	d[1][0] = 0;
	m <<= 1;
	for(int i = 1; i <= n; ++i) {
		for(int j = 0; j < m; ++j) {
			int u = edges[j].u, v = edges[j].v, t = edges[j].t, cost = edges[j].cost;
			for(map <int, int>::iterator it = d[u].begin(); it != d[u].end(); ++it) {
				if(d[v].find(it->f + t) == d[v].end() || d[u][it->f] + cost < d[v][it->f + t])
					d[v][it->f + t] = d[u][it->f] + cost;
			}
		}
	}
	for(int i = 2; i <= n; ++i) {
		ll ans = inf;
	 	for(map <int, int>::iterator it = d[i].begin(); it != d[i].end(); ++it)
			ans = min(ans, it->f * (ll)it->se);
		cout << (ans == inf ? - 1 : ans) << endl;
	}
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 413 ms 2388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2526 ms 37140 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2510 ms 16652 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2519 ms 38084 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1317 ms 131076 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2562 ms 123384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2557 ms 10168 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2530 ms 99640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2551 ms 87492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2541 ms 17756 KB Time limit exceeded
2 Halted 0 ms 0 KB -