#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);
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 (ans[a] == 0)
ans[a] = c;
if (ans[b] == 0)
ans[b] = c;
if (*mp[a].begin() == c)
ans[a] = c;
else
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';
}
# |
결과 |
실행 시간 |
메모리 |
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 |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
4 ms |
336 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
4 ms |
336 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2896 KB |
Output is correct |
2 |
Correct |
64 ms |
6324 KB |
Output is correct |
3 |
Correct |
41 ms |
4876 KB |
Output is correct |
4 |
Correct |
21 ms |
3152 KB |
Output is correct |
5 |
Correct |
6 ms |
848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
4 ms |
336 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |