# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
217486 |
2020-03-30T01:59:22 Z |
Fischer |
Ceste (COCI17_ceste) |
C++14 |
|
7 ms |
512 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);
vi tim(n+1);
for (int i = 1; i <= n; ++i) {
res[i] = LLONG_MAX;
tim[i] = INT_MAX;
}
Q.push({{0, 0}, s});
while (!Q.empty()) {
auto q = Q.top(); Q.pop();
int v = q.second;
int t = q.first.first, c = q.first.second;
res[v] = min(res[v], t*1ll*c);
if (tim[v] < t) continue;
tim[v] = min(tim[v], t);
trav(e, g[v]) {
res[e.to] = min(res[e.to], (t+e.t)*1ll*(c+e.c));
Q.push({{t+e.t, c+e.c}, 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, c, t;
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:48: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:51: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 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |