forked from wahyuhjr/OpenEmailGenerator
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLongestPath.cpp
More file actions
51 lines (42 loc) · 742 Bytes
/
LongestPath.cpp
File metadata and controls
51 lines (42 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define MAX 100
vector<ll> adj[MAX];
map<ll, ll> dp;
ll max1(ll a, ll b)
{
return (a>b?a:b);
}
void dfs(ll v, ll pv, ll n)
{
dp[v]=v;
ll mx=0;
for(auto V:adj[v])
{
if(V==pv) continue;
dfs(V,v,n);
mx=max(mx,dp[V]);
}
dp[v]+=mx;
//return dp[1];
}
int main()
{
fastio;
ll N,edge;
cin>>N>>edge;
for(ll i=0; i<edge; i++)
{
ll x,y;
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
dfs(2,3,N);
cout<<dp[2]<<"\n";
return 0;
}