This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
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}]);
}
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 |
---|
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... |