#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct edge {
int to, time, cost;
};
struct state {
int id, cost, time;
bool operator<(const state &other) const {
return cost == other.cost ? time > other.time : cost > other.cost;
}
};
int main() {
int n, m; cin >> n >> m;
vector<edge> adj[2000];
for (int i = 0; i < m; i++) {
int a, b, t, c; cin >> a >> b >> t >> c;
--a; --b;
adj[a].push_back({b,t,c});
adj[b].push_back({a,t,c});
}
int minTime[2000]; for (int i = 0; i < n; i++) minTime[i] = 1e9+10;
ll best[2000]; for (int i = 0; i < n; i++) best[i] = 9e18+10;
int mx = 2000*2000;
minTime[0] = best[0] = 0;
priority_queue<state> pq;
pq.push({0,0,0});
while (!pq.empty()) {
state u = pq.top(); pq.pop();
if (u.time > minTime[u.id]) continue;
minTime[u.id] = u.time;
best[u.id] = min(best[u.id], (ll)u.time*u.cost);
for (edge v : adj[u.id]) {
if (u.time + v.time <= mx && u.time + v.time < minTime[v.to]) {
pq.push({v.to,u.cost+v.cost,u.time+v.time});
}
}
}
for (int i = 1; i < n; i++) {
if (best[i] == 9e18+10) cout << -1 << endl;
else cout << best[i] << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
512 KB |
Output is correct |
2 |
Correct |
8 ms |
512 KB |
Output is correct |
3 |
Correct |
7 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
704 KB |
Output is correct |
2 |
Correct |
19 ms |
960 KB |
Output is correct |
3 |
Correct |
21 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
1396 KB |
Output is correct |
2 |
Correct |
126 ms |
3700 KB |
Output is correct |
3 |
Correct |
10 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
768 KB |
Output is correct |
2 |
Correct |
127 ms |
3692 KB |
Output is correct |
3 |
Correct |
13 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
760 KB |
Output is correct |
2 |
Correct |
110 ms |
1404 KB |
Output is correct |
3 |
Correct |
100 ms |
1404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
108 ms |
1396 KB |
Output is correct |
2 |
Correct |
95 ms |
1396 KB |
Output is correct |
3 |
Correct |
127 ms |
1520 KB |
Output is correct |