#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
vector<int>adj[500010];
int dep[500010];
void dfs(int x,int p)
{
dep[x]=dep[p]+1;
for(int&t:adj[x])
if(t!=p)
dfs(t,x);
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++)
{
int u,v,w;
cin>>u>>v>>w;
u++,v++;
if(w==1)
adj[u].eb(v),adj[v].eb(u);
}
dfs(1,0);
int d1=max_element(dep+1,dep+n+1)-dep;
dfs(d1,0);
cout<<2*n-1-*max_element(dep+1,dep+n+1)<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
Output is correct |
2 |
Correct |
8 ms |
12032 KB |
Output is correct |
3 |
Correct |
8 ms |
12032 KB |
Output is correct |
4 |
Correct |
8 ms |
12032 KB |
Output is correct |
5 |
Correct |
8 ms |
12032 KB |
Output is correct |
6 |
Correct |
8 ms |
12032 KB |
Output is correct |
7 |
Correct |
8 ms |
12032 KB |
Output is correct |
8 |
Correct |
10 ms |
12160 KB |
Output is correct |
9 |
Correct |
9 ms |
12032 KB |
Output is correct |
10 |
Correct |
8 ms |
12032 KB |
Output is correct |
11 |
Incorrect |
10 ms |
12032 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
Output is correct |
2 |
Correct |
8 ms |
12032 KB |
Output is correct |
3 |
Correct |
8 ms |
12032 KB |
Output is correct |
4 |
Correct |
8 ms |
12032 KB |
Output is correct |
5 |
Correct |
8 ms |
12032 KB |
Output is correct |
6 |
Correct |
8 ms |
12032 KB |
Output is correct |
7 |
Correct |
8 ms |
12032 KB |
Output is correct |
8 |
Correct |
10 ms |
12160 KB |
Output is correct |
9 |
Correct |
9 ms |
12032 KB |
Output is correct |
10 |
Correct |
8 ms |
12032 KB |
Output is correct |
11 |
Incorrect |
10 ms |
12032 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
12544 KB |
Output is correct |
2 |
Correct |
12 ms |
12672 KB |
Output is correct |
3 |
Correct |
15 ms |
12544 KB |
Output is correct |
4 |
Correct |
21 ms |
12544 KB |
Output is correct |
5 |
Correct |
12 ms |
12416 KB |
Output is correct |
6 |
Correct |
14 ms |
12416 KB |
Output is correct |
7 |
Correct |
13 ms |
12672 KB |
Output is correct |
8 |
Correct |
15 ms |
12544 KB |
Output is correct |
9 |
Correct |
12 ms |
12544 KB |
Output is correct |
10 |
Correct |
14 ms |
12544 KB |
Output is correct |
11 |
Correct |
12 ms |
12544 KB |
Output is correct |
12 |
Correct |
14 ms |
12544 KB |
Output is correct |
13 |
Correct |
12 ms |
12544 KB |
Output is correct |
14 |
Correct |
12 ms |
12544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
Output is correct |
2 |
Correct |
8 ms |
12032 KB |
Output is correct |
3 |
Correct |
8 ms |
12032 KB |
Output is correct |
4 |
Correct |
8 ms |
12032 KB |
Output is correct |
5 |
Correct |
8 ms |
12032 KB |
Output is correct |
6 |
Correct |
8 ms |
12032 KB |
Output is correct |
7 |
Correct |
8 ms |
12032 KB |
Output is correct |
8 |
Correct |
10 ms |
12160 KB |
Output is correct |
9 |
Correct |
9 ms |
12032 KB |
Output is correct |
10 |
Correct |
8 ms |
12032 KB |
Output is correct |
11 |
Incorrect |
10 ms |
12032 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
Output is correct |
2 |
Correct |
8 ms |
12032 KB |
Output is correct |
3 |
Correct |
8 ms |
12032 KB |
Output is correct |
4 |
Correct |
8 ms |
12032 KB |
Output is correct |
5 |
Correct |
8 ms |
12032 KB |
Output is correct |
6 |
Correct |
8 ms |
12032 KB |
Output is correct |
7 |
Correct |
8 ms |
12032 KB |
Output is correct |
8 |
Correct |
10 ms |
12160 KB |
Output is correct |
9 |
Correct |
9 ms |
12032 KB |
Output is correct |
10 |
Correct |
8 ms |
12032 KB |
Output is correct |
11 |
Incorrect |
10 ms |
12032 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
Output is correct |
2 |
Correct |
8 ms |
12032 KB |
Output is correct |
3 |
Correct |
8 ms |
12032 KB |
Output is correct |
4 |
Correct |
8 ms |
12032 KB |
Output is correct |
5 |
Correct |
8 ms |
12032 KB |
Output is correct |
6 |
Correct |
8 ms |
12032 KB |
Output is correct |
7 |
Correct |
8 ms |
12032 KB |
Output is correct |
8 |
Correct |
10 ms |
12160 KB |
Output is correct |
9 |
Correct |
9 ms |
12032 KB |
Output is correct |
10 |
Correct |
8 ms |
12032 KB |
Output is correct |
11 |
Incorrect |
10 ms |
12032 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
Output is correct |
2 |
Correct |
8 ms |
12032 KB |
Output is correct |
3 |
Correct |
8 ms |
12032 KB |
Output is correct |
4 |
Correct |
8 ms |
12032 KB |
Output is correct |
5 |
Correct |
8 ms |
12032 KB |
Output is correct |
6 |
Correct |
8 ms |
12032 KB |
Output is correct |
7 |
Correct |
8 ms |
12032 KB |
Output is correct |
8 |
Correct |
10 ms |
12160 KB |
Output is correct |
9 |
Correct |
9 ms |
12032 KB |
Output is correct |
10 |
Correct |
8 ms |
12032 KB |
Output is correct |
11 |
Incorrect |
10 ms |
12032 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12032 KB |
Output is correct |
2 |
Correct |
8 ms |
12032 KB |
Output is correct |
3 |
Correct |
8 ms |
12032 KB |
Output is correct |
4 |
Correct |
8 ms |
12032 KB |
Output is correct |
5 |
Correct |
8 ms |
12032 KB |
Output is correct |
6 |
Correct |
8 ms |
12032 KB |
Output is correct |
7 |
Correct |
8 ms |
12032 KB |
Output is correct |
8 |
Correct |
10 ms |
12160 KB |
Output is correct |
9 |
Correct |
9 ms |
12032 KB |
Output is correct |
10 |
Correct |
8 ms |
12032 KB |
Output is correct |
11 |
Incorrect |
10 ms |
12032 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |