이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <set>
#include <unordered_map>
int gs, edg;
std::vector<std::vector<std::pair<int,int>>> adj_list;
std::vector<std::tuple<int,int,int>> edges;
std::unordered_map<int,int> umap[500005];
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_back(b,c);
adj_list[b].emplace_back(a,c);
edges.emplace_back(a,b,c);
umap[std::min(a,b)][std::max(a,b)] = 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
for (const auto& [a, b, c] : edges) {
int x = a;
int y = b;
if (adj_list[x].size()>adj_list[y].size()) {
std::swap(x,y);
}
for (const auto& [i, w] : adj_list[x]) {
if (umap[std::min(y,i)][std::max(y,i)]!=0) {
ans = std::max(ans,(int64_t)c+w+umap[std::min(y,i)][std::max(y,i)]);
}
}
}
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... |