# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
498917 | aurims | Cheap flights (LMIO18_pigus_skrydziai) | C++14 | 121 ms | 262148 KiB |
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
using namespace std;
struct miestas
{
vector<int> kaimynai;
vector<ll> pelnas;
};
vector<miestas> miestai;
int main()
{
int N, M;
cin >> N >> M;
miestai.resize(N);
for(int i = 0; i < N; i++)
{
miestai[i].pelnas.resize(N);
for(int j = 0; j < N; j++)
{
miestai[i].pelnas[j] = -1;
}
}
for(int i = 0; i < M; i++)
{
int a, b;
ll p;
cin >> a >> b >> p;
miestai[a-1].kaimynai.pb(b-1);
miestai[b-1].kaimynai.pb(a-1);
miestai[a-1].pelnas[b-1] = p;
miestai[b-1].pelnas[a-1] = p;
}
ll mx = -1;
for(int i = 0; i < N; i++)
{
if(miestai[i].kaimynai.empty())
continue;
ll sum_tr = 0;
ll sum_zv = 0;
// perrenkam zvaigzdes
for(int sidx : miestai[i].kaimynai)
{
sum_zv += miestai[i].pelnas[sidx];
}
// perrenkam trikampius
for(int j = 0; j < miestai[i].kaimynai.size()-1; j++)
{
int kaim1 = miestai[i].kaimynai[j];
int kaim2 = miestai[i].kaimynai[j+1];
if(miestai[kaim1].pelnas[kaim2] != -1) // jeigu i-tojo miesto kaimynai j ir j+1 irgi turi kelia, tai susidaro trikampis
sum_tr = miestai[i].pelnas[kaim1]+miestai[i].pelnas[kaim2]+miestai[kaim1].pelnas[kaim2];
}
if(sum_zv > sum_tr)
if(sum_zv > mx)
mx = sum_zv;
else
if(sum_tr > mx)
mx = sum_tr;
}
cout << mx << '\n';
}
Compilation message (stderr)
# | 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... |