Submission #1129998

#TimeUsernameProblemLanguageResultExecution timeMemory
11299988pete8Cheap flights (LMIO18_pigus_skrydziai)C++20
100 / 100
583 ms66356 KiB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include <cstdint>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
#define int long long
#define double long double
const int mod=1e9+7,mxn=3e5+5,lg=30,inf=1e18,minf=-1e18;
int n,m;
vector<pii>adj[mxn+10];
map<pii,int>mp;
int32_t main(){
	fastio
	cin>>n>>m;
	int ans=0;
	for(int i=0;i<m;i++){
		int a,b,c;cin>>a>>b>>c;
		adj[a].pb({c,b});
		adj[b].pb({c,a});
		mp[{min(a,b),max(a,b)}]=c;
	}
	for(int i=1;i<=n;i++){
		int x=0;
		for(auto j:adj[i])x+=j.f;
		ans=max(ans,x);
		for(int j=0;j<min((int)adj[i].size(),3LL);j++)for(int k=j+1;k<min((int)adj[i].size(),3LL);k++){
			ans=max(ans,adj[i][j].f+adj[i][k].f+mp[{min(adj[i][j].s,adj[i][k].s),max(adj[i][j].s,adj[i][k].s)}]);
		}
	}
	cout<<ans;

}
/*
finding max triangle??
claim : the triangle that might be a possible answer need to use atleast 1 edge from top 3 of a node
how about 2 edge???
proof:
triangle consist of edge a,b,c where a<=b<=c
if b,c connected to x
if b,c is not in the first 3 max edge when sorted edge of x by cost 
then we can obviously get a better answer using sum of x ?
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...