#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) {}
};
const int inf = 2e9;
const int N = 2e3 + 15;
int n, m, ans[N];
map <int, int> d[N];
vector <edge> g[N];
bool used[N];
void dfs(int v, int t = 0, int cost = 0) {
d[v][t] = cost;
used[v] = true;
for(edge e : g[v]) {
if(used[e.to])
continue;
if(d[e.to].empty() || d[e.to].find(t + e.t) == d[e.to].end() || d[e.to][t + e.t] > cost + e.cost)
dfs(e.to, t + e.t, cost + e.cost);
}
used[v] = false;
}
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;
g[u].pb(*new edge(v, t, c));
g[v].pb(*new edge(u, t, c));
}
dfs(1);
for(int i = 2; i <= n; ++i) {
int ans = inf;
for(map <int, int>::iterator it = d[i].begin(); it != d[i].end(); ++it)
ans = min(ans, it->f * it->se);
cout << (ans == inf ? - 1 : ans) << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
336 ms |
2696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
1336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1622 ms |
131072 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 |
2534 ms |
23412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1915 ms |
131072 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 |
2536 ms |
77060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2529 ms |
29864 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1421 ms |
131076 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |