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>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
#define ll long long
#define ff first
#define ss second
#define int ll
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define pii pair <int, int>
#define pdd pair <double, double>
#define vi vector <int>
using namespace std;
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const int inf = 1e15;
const int mod = 1e9+7;
const int N = 2e5+100;
void solve(){
int n, m;
cin >> n >> m;
map <pii, int> e;
vector <vector <pii> > g(n+10);
for (int i = 0; i < m; ++i){
int a, b, w; cin >> a >> b >> w;
g[a].pb({w, b});
g[b].pb({w, a});
e[{a, b}] = w;
e[{b, a}] = w;
}
int ans = 0;
for (int v = 1; v <= n; ++v){
sort(rall(g[v]));
int res = 0;
for (auto i : g[v]) res += i.ff;
if (g[v].size() > 1){
auto x = g[v][0], y = g[v][1];
res = max(res, x.ff + y.ff + e[{x.ss, y.ss}]);
}
ans = max(ans, res);
}
cout << ans;
}
signed main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int tt = 1;
while (tt--){
solve();
cout << '\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... |