# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198167 | model_code | Cheap flights (LMIO18_pigus_skrydziai) | C++14 | 1586 ms | 63060 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 <cstdio>
#include <cstdint>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
const int64_t MAX_N = 300000 + 100;
map<pair<int64_t, int64_t>, int64_t> briaunos;
pair<int,int64_t> sunkiausi[MAX_N][2];
int64_t zvaigzde[MAX_N];
void AtnaujintiSunkiausius(int v, int w, int64_t svoris)
{
if (sunkiausi[v][0].second < svoris) {
sunkiausi[v][1] = sunkiausi[v][0];
sunkiausi[v][0] = make_pair(w, svoris);
}
else if (sunkiausi[v][1].second < svoris) {
sunkiausi[v][1] = make_pair(w, svoris);
}
}
int main()
{
int N, M;
scanf("%d%d", &N, &M);
for (int i = 0; i < N; ++i) {
sunkiausi[i][0] = make_pair(-1, -1);
sunkiausi[i][1] = make_pair(-1, -1);
zvaigzde[i] = 0;
}
for (int j = 0; j < M; ++j) {
int a, b, svoris;
scanf("%d%d%d", &a, &b, &svoris);
AtnaujintiSunkiausius(a - 1, b - 1, svoris);
AtnaujintiSunkiausius(b - 1, a - 1, svoris);
zvaigzde[a - 1] += (int64_t) svoris;
zvaigzde[b - 1] += (int64_t) svoris;
briaunos[make_pair(a - 1, b - 1)] = (int64_t) svoris;
briaunos[make_pair(b - 1, a - 1)] = (int64_t) svoris;
}
int64_t atsakymas = 0;
for (int i = 0; i < N; ++i) {
if (zvaigzde[i] > atsakymas)
atsakymas = zvaigzde[i];
if (sunkiausi[i][1].first != -1) {
map<pair<int64_t, int64_t>, int64_t>::iterator it = briaunos.find(make_pair(sunkiausi[i][0].first, sunkiausi[i][1].first));
if (it != briaunos.end()) {
int64_t trikampis = sunkiausi[i][0].second + sunkiausi[i][1].second + it->second;
if (trikampis > atsakymas)
atsakymas = trikampis;
}
}
}
printf("%lld\n", atsakymas);
return 0;
}
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... |