#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 |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
7 ms |
1616 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
6 ms |
1360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
7 ms |
1616 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
6 ms |
1360 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
2668 KB |
Output is correct |
2 |
Correct |
40 ms |
6216 KB |
Output is correct |
3 |
Correct |
28 ms |
4656 KB |
Output is correct |
4 |
Correct |
18 ms |
2896 KB |
Output is correct |
5 |
Correct |
3 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
7 ms |
1616 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
6 ms |
1360 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
16 ms |
2668 KB |
Output is correct |
17 |
Correct |
40 ms |
6216 KB |
Output is correct |
18 |
Correct |
28 ms |
4656 KB |
Output is correct |
19 |
Correct |
18 ms |
2896 KB |
Output is correct |
20 |
Correct |
3 ms |
848 KB |
Output is correct |
21 |
Correct |
74 ms |
8008 KB |
Output is correct |
22 |
Correct |
82 ms |
8520 KB |
Output is correct |
23 |
Correct |
113 ms |
9288 KB |
Output is correct |
24 |
Correct |
110 ms |
11336 KB |
Output is correct |
25 |
Correct |
206 ms |
15432 KB |
Output is correct |