# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
795926 | allllekssssa | Cheap flights (LMIO18_pigus_skrydziai) | C++14 | 256 ms | 66400 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<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
const int maxN = 1e6 + 10;
vector<pii> v[maxN], v1[maxN];
long long cnt[maxN];
int n, m;
int mx;
int main() {
cin >> n >> m;
for (int i = 1; i<=m; i++) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
cnt[x]+=z;
cnt[y]+=z;
v[x].pb(mp(y,z));
v[y].pb(mp(x, z));
}
long long ans = 0;
for (int i = 1; i<=n; i++) {
ans = max(ans, cnt[i]);
}
for (int i = 1; i<= n; i++) {
for (auto j: v[i]) {
if (j.first > i) continue;
int x = i;
int y = j.first;
int z = j.second;
if (v[x].size() > v[y].size()) swap(x, y);
v1[x].pb(mp(y, z));
}
}
for (int i = 1; i<=n; i++) {
for (auto j: v1[i]) {
for (auto k: v1[i])
cnt[k.first] = k.second;
for (auto k: v1[j.first]) {
cnt[k.first]+=k.second;
ans = max(ans, j.second + cnt[k.first]);
cnt[k.first] = 0;
}
for (auto k: v1[i]) {
cnt[k.first] = 0;
}
}
}
cout << ans << endl;
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... |