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>
#define int ll
#define all(v) v.begin(), v.end()
// author : a1abay
using namespace std;
typedef long long ll;
typedef long double ld;
const int sz = 3e5 + 5;
const int inf = 1e9 + 7;
int n, m, ans, u, v, w;
vector<array<int, 2>> g[sz];
map<array<int, 2>, int> e;
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
cin >> u >> v >> w;
g[u].push_back({w, v});
g[v].push_back({w, u});
e[{u, v}] = w;
e[{v, u}] = w;
}
for(int i = 1; i <= n; i++)
{
sort(all(g[i]));
reverse(all(g[i]));
int s = 0;
for(auto p : g[i]) s += p[0];
ans = max(ans, s);
}
for(int i = 1; i <= n; i++)
{
if(g[i].size() < 2) continue;
if(!e[{g[i][0][1], g[i][1][1]}]) continue;
ans = max(ans, g[i][0][0] + g[i][1][0] + e[{g[i][0][1], g[i][1][1]}]);
}
cout << ans;
}
# | 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... |