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 ferries(int n , int m , vector<int> a , vector<int> b , vector<int> c) {
vector<vector<pair<int , int>>> adj(n);
for (int i = 0 ; i < m ; i++) {
a[i] -= 1 , b[i] -= 1;
adj[a[i]].emplace_back(b[i] , c[i]);
}
vector<int> s , d;
for (int i = 0 ; i < (int)adj[0].size() ; i += 1) {
s.push_back(adj[0][i].second);
}
sort(s.begin() , s.end());
for (int i = 1 ; i < n - 1 ; i += 1) {
d.push_back(adj[i][0].second);
}
sort(d.begin() , d.end());
assert((int)s.size() == (int)d.size());
auto Get = [&]() {
int val = (int)1e9;
for (int i = 0 ; i < (int)s.size() ; i += 1) {
val = min(val , s[i] + d[(int)s.size() - 1 - i]);
}
return val;
};
int res = Get();
reverse(s.begin() , s.end());
reverse(d.begin() , d.end());
res = max(res , Get());
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n , m;
cin >> n >> m;
vector<int> a(m) , b(m) , c(m);
for (int i = 0 ; i < m ; i += 1) {
cin >> a[i] >> b[i] >> c[i];
}
cout << ferries(n , m , a , b , c) << '\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... |