Submission #247397

# Submission time Handle Problem Language Result Execution time Memory
247397 2020-07-11T10:16:50 Z dolphingarlic Cheap flights (LMIO18_pigus_skrydziai) C++14
0 / 100
350 ms 47736 KB
/*
LMIO 2018 Pigus Skrydziai
- We either take all edges incident to one node or we take a triangle
- There are 
*/

#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

ll prof[300001], max_triangle = 0;
vector<pair<int, ll>> graph[300001];
map<pair<int, int>, ll> edges;
bool visited[300001];

void dfs(int node) {
    visited[node] = true;
    for (pair<int, ll> i : graph[node]) {
        if (!visited[i.first]) {
            for (pair<int, ll> j : graph[i.first]) {
                max_triangle = max(max_triangle, i.second + j.second + edges[{node, j.first}]);
            }
        }
    }
    for (pair<int, ll> i : graph[node]) {
        if (!visited[i.first]) dfs(i.first);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    while (m--) {
        int a, b;
        ll v;
        cin >> a >> b >> v;
        prof[a] += v, prof[b] += v;
        graph[a].push_back({b, v});
        graph[b].push_back({a, v});
        edges[{a, b}] = edges[{b, a}] = v;
    }
    FOR(i, 1, n + 1) if (!visited[i]) dfs(i);
    cout << max(max_triangle, *max_element(prof + 1, prof + n + 1));
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Incorrect 8 ms 7424 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 8 ms 7424 KB Output is correct
3 Incorrect 8 ms 7424 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 350 ms 47736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 350 ms 47736 KB Output isn't correct
2 Halted 0 ms 0 KB -