# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
213623 | SamAnd | Cheap flights (LMIO18_pigus_skrydziai) | C++17 | 1453 ms | 85244 KiB |
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;
#define m_p make_pair
const int N = 500005;
int n, m;
vector<pair<int, int> > a[N];
map<pair<int, int>, int> mp;
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i)
{
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
a[x].push_back(m_p(z, y));
a[y].push_back(m_p(z, x));
mp[m_p(x, y)] = z;
mp[m_p(y, x)] = z;
}
long long ans = 0;
for (int x = 1; x <= n; ++x)
{
long long yans = 0;
for (int i = 0; i < a[x].size(); ++i)
{
yans += a[x][i].first;
}
ans = max(ans, yans);
}
for (int x = 1; x <= n; ++x)
{
sort(a[x].begin(), a[x].end());
reverse(a[x].begin(), a[x].end());
if (a[x].size() >= 2 && mp.find(m_p(a[x][0].second, a[x][1].second)) != mp.end())
ans = max(ans, a[x][0].first + 0LL + a[x][1].first + mp[m_p(a[x][0].second, a[x][1].second)]);
}
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | 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... |