#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 = 300001, dim2 = 500001, mod = 1e9+7;
int n, m, i, j;
ll gr[dim];
vector<pint> g[dim];
map<int, int> ma[dim];
struct muchie {
int a, b, c;
} lm[dim2];
void solve()
{
cin >> n >> m;
int a, b, c;
ll profit = 0;
for (i = 1; i <= m; i++)
{
cin >> a >> b >> c;
lm[i] = {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 <= 5000)
{
for (i = 1; i <= m; i++)
{
int a = lm[i].a, b = lm[i].b, c = lm[i].c;
for (auto x : g[a])
{
ll cost = (ll)c+x.ss+ma[x.ff][b];
if (x.ff != b && ma[x.ff][b])
profit = max(profit, cost);
}
for (auto x : g[b])
{
ll cost = (ll)c+x.ss+ma[x.ff][a];
if (x.ff != a && ma[x.ff][a])
profit = max(profit, cost);
}
}
}
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... |