#include <bits/stdc++.h>
using namespace std ;
const int MAX = 5e5 + 10 ;
int vis[MAX] , mark[MAX] , dep[MAX] ;
int n , m ;
vector< vector< pair<int , int> > >adj(MAX) ;
long long ans = 0ll ;
void dfs(int node , long long x , long long y)
{
vis[node] = mark[node] = 1 ;
long long sum = 0 ;
for(auto &child : adj[node])
{
ans = max(ans , y + child.second) ;
int to = child.first ;
sum += child.second ;
if(vis[to])
{
if(mark[to] && dep[to] == dep[node] - 2)
ans = max(ans , x + y + child.second) ;
continue ;
}
dep[to] = dep[node] + 1 ;
dfs(to , y , child.second) ;
}
ans = max(ans , sum) ;
mark[node] = 0 ;
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>m ;
for(int i = 0 ; i < m ; ++i)
{
int x , y , z ;
cin>>x>>y>>z ;
adj[x].emplace_back(y , z) ;
adj[y].emplace_back(x , z) ;
}
for(int i = 1 ; i <= n ; ++i)
{
if(!vis[i])
dfs(i , 0 , 0) ;
}
return cout<<ans<<"\n" , 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12140 KB |
Output is correct |
2 |
Correct |
9 ms |
12140 KB |
Output is correct |
3 |
Incorrect |
8 ms |
12140 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12140 KB |
Output is correct |
2 |
Correct |
9 ms |
12140 KB |
Output is correct |
3 |
Incorrect |
8 ms |
12140 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
114 ms |
24940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
114 ms |
24940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |