# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
243220 | Nightlight | Cheap flights (LMIO18_pigus_skrydziai) | C++14 | 526 ms | 32180 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 pii pair<int, int>
#define piii tuple<int, int, int>
using namespace std;
int N, M;
vector<pii> adj[300005];
int deg[300005];
long long res[300005];
piii edge[300005];
int vis[300005];
long long ada[300005];
long long ans;
bool comp(int a, int b) {
return deg[a] == deg[b] ? a > b : deg[a] > deg[b];
}
int main() {
scanf("%d %d", &N, &M);
int u, v, w;
for(int i = 1; i <= M; i++) {
scanf("%d %d %d", &u, &v, &w);
deg[u]++, deg[v]++;
ada[u] += w, ada[v] += w;
edge[i] = make_tuple(u, v, w);
}
for(int i = 1; i <= M; i++) {
tie(u, v, w) = edge[i];
if(comp(u, v)) adj[u].emplace_back(v, w);
else adj[v].emplace_back(u, w);
}
for(int u = 1; u <= N; u++) {
ans = max(ans, ada[u]);
for(pii v : adj[u]) {
vis[v.first] = v.second;
}
for(pii v : adj[u]) {
for(pii w : adj[v.first]) {
if(vis[w.first]) {
ans = max(ans, (long long) vis[v.first] + vis[w.first] + w.second);
}
}
}
for(pii v : adj[u]) {
vis[v.first] = 0;
}
}
printf("%lld\n", ans);
cin >> 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... |