제출 #1129993

#제출 시각아이디문제언어결과실행 시간메모리
11299938pete8Cheap flights (LMIO18_pigus_skrydziai)C++20
16 / 100
535 ms60544 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; sort(all(adj[i])); for(auto j:adj[i])x+=j.f; ans=max(ans,x); if(adj[i].size()>1){ ans=max(ans,adj[i][0].f+adj[i][1].f+mp[{min(adj[i][0].s,adj[i][1].s),max(adj[i][0].s,adj[i][1].s)}]); } } cout<<ans; } /* finding max triangle?? claim : the triangle that might be a possible answer need to use atleast 2 max edge of a node proof: triangle consist of edge a,b,c where a<=b<=c if b,c connected to x if b,c is not the first 2 max edge when sorted edge of x by cost we can get a better answer using the sum of edge of x ex. let sorted order be [g,b,c] because a<=b<=c a+b+c<= 2*b+c <= g+b+c is this correct?? */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...