#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, char>
#define pint pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
#define allsir(v) v+1, v+n+1
#define inf 1e9
using namespace std;
const string file = "";
ifstream fin(file+".in");
ofstream fout(file+".out");
const int dim = 500001, mod = 1e9+7;
int n, m, i, j;
ll gr[dim];
vector<pint> g[dim];
unordered_map<int, ll> ma[dim];
void solve()
{
cin >> n >> m;
int a, b, c;
ll profit = 0;
for (i = 1; i <= m; i++)
{
cin >> a >> b >> c;
gr[a] += c;
gr[b] += c;
profit = max(profit, gr[a]);
profit = max(profit, gr[b]);
g[a].pb({b, c});
g[b].pb({a, c});
ma[a][b] = c;
ma[b][a] = c;
}
if (n <= 200)
{
for (int nod = 1; nod <= n; nod++)
{
for (i = 0; i < g[nod].size(); i++)
for (j = i+1; j < g[nod].size(); j++)
{
int n2 = g[nod][i].ff, n3 = g[nod][j].ff;
if (ma[n2][n3])
profit = max(profit, ma[nod][n2]+ma[nod][n3]+ma[n2][n3]);
}
}
}
cout << profit;
}
int main()
{
int t = 1;
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
//cin >> t;
while (t--)
solve();
return 0;
}
# | 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... |