Submission #382169

#TimeUsernameProblemLanguageResultExecution timeMemory
382169mohamedsobhi777Cheap flights (LMIO18_pigus_skrydziai)C++14
12 / 100
3083 ms70080 KiB
#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define pb push_back
#define f first
#define s second
#define sz(_) ((int)_.size())
#define all(_) _.begin(), _.end()
#define lb lower_bound
#define ub upper_bound

using ll = long long;
using ld = long double;

const int N = 3e5 + 7;
const ll mod = 1e9 + 7;

int n, m;
ll a[N];
map<pii, ll> cost;

int main()
{
       ios_base::sync_with_stdio(0);
       cin.tie(0);
#ifndef ONLINE_JUDGE
#endif
       cin >> n >> m;
       ll ans = 0;

       bool case3 = 1;

       for (int i = 0; i < m; ++i)
       {
              int u, v, w;
              cin >> u >> v >> w;
              a[u] += w;
              a[v] += w;
              ans = max({ans, a[u], a[v]});
              cost[{u, v}] = cost[{v, u}] = w;
              case3 &= w == 1;
       }

       if (case3 && m >= n)
       {
              ans = max(ans, 3ll);
       }
       else
       {

              for (int i = 1; i <= n; ++i)
              {
                     for (int j = i + 1; j <= n; ++j)
                     {
                            for (int k = j + 1; k <= n; ++k)
                            {
                                   if (cost[{i, j}] && cost[{i, k}] && cost[{j, k}])
                                   {
                                          ans = max(ans, cost[{i, j}] + cost[{j, k}] + cost[{i, k}]);
                                   }
                            }
                     }
              }
       }

       cout << ans;
       return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...