This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define debug cout << "alio\n"
#define pb push_back
#define ll long long
#define MAX (int)3e5
using namespace std;
vector<ll> adj[MAX];
map<pair<ll, ll>, ll> pe;
int main()
{
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int N, M;
cin >> N >> M;
for(int i = 0; i < M; i++)
{
ll a, b;
ll p;
cin >> a >> b >> p;
adj[a-1].pb(b-1);
adj[b-1].pb(a-1);
pe[{a-1, b-1}] = p;
pe[{b-1, a-1}] = p;
}
ll mx = -1;
for(int i = 0; i < N; i++)
{
if(adj[i].empty())
continue;
ll sum_tr = 0;
ll sum_zv = 0;
// perrenkam zvaigzdes
for(ll sidx : adj[i])
{
sum_zv += pe[{i, sidx}];
}
// perrenkam trikampius
for(int j = 0; j < adj[i].size()-1; j++)
{
ll kaim1 = adj[i][j];
ll kaim2 = adj[i][j+1];
if(pe.find({kaim1, kaim2}) != pe.end()) // jeigu i-tojo miesto kaimynai j ir j+1 irgi turi kelia, tai susidaro trikampis
sum_tr = pe[{kaim1, kaim2}] + pe[{i, kaim1}] + pe[{i, kaim2}];
}
if(sum_zv > mx) mx = sum_zv;
if(sum_tr > mx) mx = sum_tr;
}
cout << mx << '\n';
}
Compilation message (stderr)
pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int j = 0; j < adj[i].size()-1; j++)
| ~~^~~~~~~~~~~~~~~~~
# | 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... |