Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <fstream>
  2. #include <vector>
  3.  
  4. typedef struct v
  5. {
  6. int begin;
  7. int end;
  8. int weight;
  9. };
  10.  
  11. int main()
  12. {
  13. std::ifstream fin;
  14. std::ofstream fout;
  15. fin.open("input.txt", std::ios::in);
  16. fout.open("output.txt", std::ios::out);
  17. int n, m;
  18. fin >> n >> m;
  19. std::vector<v> arr(m);
  20. for (int i = 0; i < m; ++i)
  21. {
  22. fin >> arr[i].begin >> arr[i].end >> arr[i].weight;
  23. }
  24.  
  25. for (int i = 0; i < m - 1; ++i)
  26. for (int j = i + 1; j < m; ++j)
  27. if (arr[i].begin == arr[j].begin && arr[i].end == arr[j].end ||
  28. arr[i].begin == arr[j].end && arr[i].end == arr[j].end)
  29. {
  30. int max_weight = std::max(arr[i].weight, arr[j].weight);
  31. arr[i].weight = max_weight;
  32. arr[j].weight = max_weight;
  33. }
  34. int max = 0;
  35. for (int i = 0; i < m; ++i)
  36. if (arr[i].weight > max)
  37. max = arr[i].weight;
  38. fout << max;
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement