#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#define ULL unsigned long long
using namespace std;
int nodes, edges;
ULL costs[300003], ans;
vector <int> graph[300005];
map <pair <int, int>, ULL> frecv;
bool viz[300005];
void dfs (int current, int previous){
viz[current] = true;
for (auto future:graph[current]){
if (viz[future] == false){
dfs(future, current);
}
else if (viz[future] == true && frecv.find({future, previous}) != frecv.end()){
ans = max(ans, frecv[{previous, current}] + frecv[{current, future}] + frecv[{previous, future}]);
}
}
}
int main (){
int x, y, cost;
cin >> nodes >> edges;
/// exista doua sub grafuri pe care le pot luat pentru a ajunge la ce vreau
/// o stea, sau un subgraf care e complet
for (int i=1; i<=edges; ++i){
cin >> x >> y >> cost;
costs[x] += cost;
costs[y] += cost;
graph[x].push_back(y);
graph[y].push_back(x);
frecv[{x, y}] = cost;
frecv[{y, x}] = cost;
}
for (int i=1; i<=nodes; ++i){
ans = max(ans, costs[i]);
}
for (int i=1; i<=nodes; ++i){
if (viz[i] == false)
dfs(i, 0);
}
cout << ans;
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... |