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 <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <set>
int gs, edg;
std::vector<std::set<std::pair<int,int>>> adj_list;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
std::cin >> gs >> edg;
adj_list.resize(gs+1);
for (int i = 0, a, b, c; i < edg; i++) {
std::cin >> a >> b >> c;
adj_list[a].emplace(b,c);
adj_list[b].emplace(a,c);
}
// try all star graphs
int64_t ans = 0;
for (int i = 1; i <= gs; i++) {
int64_t cand = 0;
for (const auto& [j, w] : adj_list[i]) {
cand += w;
}
ans = std::max(ans,cand);
}
// try all "triangle" cycles
if (ans<=3000000000)
for (int i = 1; i <= gs; i++) {
if (adj_list[i].size()<2) {
continue;
}
for (const auto& [j, wj] : adj_list[i]) {
if (j<i) {
continue;
}
for (const auto& [k, wk] : adj_list[j]) {
if (k<j) {
continue;
}
if (k==i) {
continue;
}
auto it = adj_list[k].lower_bound(std::pair<int,int>(i,0));
if (it!=adj_list[k].end()&&it->first==i) {
//std::cout << i << " " << j << " " << k << "\n";
//std::cout << wj << " " << wk << " " << it->second << "\n";
ans = std::max(ans, static_cast<int64_t>(wj)+wk+it->second);
}
}
}
}
std::cout << ans << "\n";
}
# | 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... |