이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |