File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed
Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+ #include < algorithm>
3+ #include < vector>
4+ using namespace std ;
5+ #define ll long long
6+ #define fastio ios_base::sync_with_stdio (0 ); cin.tie(0 );
7+ #define MAX 100
8+
9+ vector<ll> adj[MAX];
10+ map<ll, ll> dp;
11+
12+ ll max1 (ll a, ll b)
13+ {
14+ return (a>b?a:b);
15+ }
16+ void dfs (ll v, ll pv, ll n)
17+ {
18+
19+ dp[v]=v;
20+ ll mx=0 ;
21+ for (auto V:adj[v])
22+ {
23+ if (V==pv) continue ;
24+ dfs (V,v,n);
25+ mx=max (mx,dp[V]);
26+ }
27+ dp[v]+=mx;
28+
29+ // return dp[1];
30+ }
31+ int main ()
32+ {
33+ fastio;
34+ ll N,edge;
35+ cin>>N>>edge;
36+
37+
38+ for (ll i=0 ; i<edge; i++)
39+ {
40+ ll x,y;
41+ cin>>x>>y;
42+ adj[x].push_back (y);
43+ adj[y].push_back (x);
44+ }
45+ dfs (2 ,3 ,N);
46+ cout<<dp[2 ]<<" \n " ;
47+
48+
49+ return 0 ;
50+ }
51+
You can’t perform that action at this time.
0 commit comments