이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pii;
const int maxn = 2010;
const int maxv = 2010*2010;
const ll inf = 1e18+10;
int n, m;
ll ans[maxn];
unordered_map<int, bool> mark[maxn];
vector<pair<pii, int>> grafo[maxn];
void dijkstra(void)
{
priority_queue<pair<pii, pii>, vector<pair<pii, pii>>, greater<pair<pii, pii>>> fila;
fila.push({{0, 1}, {0, 0}});
while (!fila.empty())
{
int u = fila.top().first.second, sum_t = fila.top().second.first, sum_c = fila.top().second.second;
ll cost = fila.top().first.first;
fila.pop();
if (mark[u][sum_t]) continue;
if (!ans[u]) ans[u] = cost;
mark[u][sum_t] = 1;
for (auto pp: grafo[u])
{
int v = pp.second, t = pp.first.first, c = pp.first.second;
if (sum_t+t < maxv && sum_c+c < maxv)
fila.push({{1ll*(sum_t+t)*(sum_c+c), v}, {sum_t+t, sum_c+c}});
}
}
}
int main(void)
{
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({{t, c}, v});
grafo[v].push_back({{t, c}, u});
}
dijkstra();
for (int i = 2; i <= n; i++)
{
if (ans[i] == 0) printf("-1\n");
else printf("%lld\n", ans[i]);
}
}
컴파일 시 표준 에러 (stderr) 메시지
ceste.cpp: In function 'int main()':
ceste.cpp:50: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:55: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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |