//struct Edge {int u, v, weight;bool operator<(Edge const& other) {return weight < other.weight;}};
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define sp ' '
#define pb push_back
#define ar for(int i=1;i<=n;i++)
using namespace std;
ll t=1;
const ll N=3e5+100;
ll n,m,q,k;
ll a[N],b[N],c[N];
bool vis[N];
ll mx=0;
ll ans=0;
ll last;
vector<int>vnum;
vector<int>v[N];
void dfs(ll x,ll y)
{
vnum.push_back(x);
vis[x]=1;
if(mx<y){
mx=max(mx,y);last=x;}
for(auto i:v[x])
{
if(!vis[i]){dfs(i,y+1);}
}
}
void solve()
{
cin>>n>>m;
while(m--)
{
ll x,y;cin>>x>>y;
v[x].push_back(y);
v[y].push_back(x);
}
for(int i=1;i<=n;i++)
{
if(!vis[i])
{
vnum.clear();
mx=0;
last=0;
dfs(i,1);
mx=0;
if(last==0){continue;}
for(auto i:vnum){vis[i]=0;}
dfs(last,1);
ans+=mx;
}
}
cout<<ans<<endl;return;
}
int main()
{
//freopen("shell.in", "r", stdin);
// freopen("shell.out", "w", stdout);
ios::sync_with_stdio(NULL);
cin.tie(NULL);cout.tie(NULL);
// cin>>t;
while(t--){solve();}
return 0;
}
//09:00 :: 9:45
//10:30 ::
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9820 KB |
Output is correct |
2 |
Correct |
11 ms |
10712 KB |
Output is correct |
3 |
Correct |
15 ms |
11488 KB |
Output is correct |
4 |
Correct |
22 ms |
12756 KB |
Output is correct |
5 |
Correct |
24 ms |
13512 KB |
Output is correct |
6 |
Correct |
37 ms |
14348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
19924 KB |
Output is correct |
2 |
Correct |
4 ms |
9304 KB |
Output is correct |
3 |
Correct |
6 ms |
9616 KB |
Output is correct |
4 |
Correct |
8 ms |
10300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9048 KB |
Output is correct |
2 |
Correct |
2 ms |
8792 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8792 KB |
Output is correct |
5 |
Correct |
6 ms |
9564 KB |
Output is correct |
6 |
Correct |
7 ms |
10452 KB |
Output is correct |
7 |
Correct |
9 ms |
11232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
3 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8792 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
3 ms |
8792 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
9820 KB |
Output is correct |
2 |
Correct |
11 ms |
10712 KB |
Output is correct |
3 |
Correct |
15 ms |
11488 KB |
Output is correct |
4 |
Correct |
22 ms |
12756 KB |
Output is correct |
5 |
Correct |
24 ms |
13512 KB |
Output is correct |
6 |
Correct |
37 ms |
14348 KB |
Output is correct |
7 |
Correct |
28 ms |
19924 KB |
Output is correct |
8 |
Correct |
4 ms |
9304 KB |
Output is correct |
9 |
Correct |
6 ms |
9616 KB |
Output is correct |
10 |
Correct |
8 ms |
10300 KB |
Output is correct |
11 |
Correct |
2 ms |
9048 KB |
Output is correct |
12 |
Correct |
2 ms |
8792 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8792 KB |
Output is correct |
15 |
Correct |
6 ms |
9564 KB |
Output is correct |
16 |
Correct |
7 ms |
10452 KB |
Output is correct |
17 |
Correct |
9 ms |
11232 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
2 ms |
8796 KB |
Output is correct |
20 |
Correct |
2 ms |
8796 KB |
Output is correct |
21 |
Correct |
2 ms |
8796 KB |
Output is correct |
22 |
Correct |
3 ms |
8792 KB |
Output is correct |
23 |
Correct |
2 ms |
8796 KB |
Output is correct |
24 |
Correct |
2 ms |
8792 KB |
Output is correct |
25 |
Correct |
2 ms |
8792 KB |
Output is correct |
26 |
Correct |
2 ms |
8796 KB |
Output is correct |
27 |
Correct |
3 ms |
8792 KB |
Output is correct |
28 |
Correct |
2 ms |
8796 KB |
Output is correct |
29 |
Correct |
32 ms |
14536 KB |
Output is correct |
30 |
Correct |
10 ms |
9816 KB |
Output is correct |
31 |
Correct |
19 ms |
12636 KB |
Output is correct |
32 |
Correct |
12 ms |
10588 KB |
Output is correct |
33 |
Correct |
24 ms |
12964 KB |
Output is correct |
34 |
Correct |
20 ms |
11228 KB |
Output is correct |
35 |
Correct |
23 ms |
12628 KB |
Output is correct |
36 |
Correct |
24 ms |
12504 KB |
Output is correct |
37 |
Correct |
35 ms |
12880 KB |
Output is correct |
38 |
Correct |
29 ms |
13528 KB |
Output is correct |
39 |
Correct |
22 ms |
12632 KB |
Output is correct |