# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1237801 | Geforgs | Cheap flights (LMIO18_pigus_skrydziai) | C11 | 0 ms | 0 KiB |
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
#define ll long long
#define ld long double
#define inf (ll)(2*1e18)
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
#define pb push_back
#define endl "\n"
using namespace std;
void solve(){
ll n, m, i, x, y, w, res=0, cnt;
cin>>n>>m;
vector<map<ll, ll>> a(n);
vector<set<pair<ll, ll>>> b(n);
for(i=0;i<m;++i){
cin>>x>>y>>w;
--x;
--y;
a[x][y] = w;
a[y][x] = w;
b[x].insert({w, y});
b[y].insert({w, x});
}
for(i=0;i<n;++i){
cnt = 0;
for(auto el: a[i]){
cnt += el.second;
}
res = max(res, cnt);
cnt = 0;
if(b[i].size() > 2){
x = b[i].rbegin()->second;
b[i].erase(*b[i].rbegin());
y = b[i].rbegin()->second;
cnt = a[i][x] + a[i][y] + a[x][y];
}
res = max(res, cnt);
}
cout<<res<<endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
srand(time(nullptr));
ll t=1;
// cin>>t;
for(;t>0;--t){
solve();
}
return 0;
}