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;
bool comp(array <int, 3> a, array <int, 3> b) {
return a[2] < b[2];
}
int main() {
int n, m;
cin >> n >> m;
map <int, multiset <int>> mp;
vector <array <int, 3>> nums(m);
for (int i = 0; i < m; i++) {
cin >> nums[i][0] >> nums[i][1] >> nums[i][2];
mp[nums[i][0]].insert(nums[i][2]);
mp[nums[i][1]].insert(nums[i][2]);
}
vector <int> ans(n+1, 1e9);
sort(nums.begin(), nums.end(), comp);
for (int i = 0; i < m; i++) {
int a = nums[i][0], b = nums[i][1], c = nums[i][2];
if (*mp[a].begin() == c)
ans[a] = c;
if (*mp[b].begin() == c)
ans[b] = c;
mp[a].erase(mp[a].find(c));
mp[b].erase(mp[b].find(c));
}
for (int i = 1; i <= n; i++)
cout << ans[i] << ' ';
cout << '\n';
}
# | 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... |