This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int N, M;
cin >> N >> M;
vector<int> Tab(N);
for (int i = 0; i < N; i++)
cin >> Tab[i];
vector<vector<pair<int, int>>> AR(N);
for (int i = 0; i < M; i++)
{
int a, b, c;
cin >> a >> b >> c;
a--, b--;
AR[a].push_back({b, c});
AR[b].push_back({a, c});
}
priority_queue<pair<int, int>> PQ;
for (int i = 0; i < N; i++)
PQ.push({Tab[i], i});
vector<int> best(N, -1);
while (!PQ.empty())
{
int x = PQ.top().second, y = PQ.top().first;
PQ.pop();
if (best[x] != -1)
continue;
best[x] = y;
for (int i = 0; i < AR[x].size(); i++)
{
PQ.push({y - AR[x][i].second, AR[x][i].first});
}
}
for (int i = 0; i < N; i++)
{
cout << best[i] << '\n';
}
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:30:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i = 0; i < AR[x].size(); i++)
| ~~^~~~~~~~~~~~~~
# | 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... |