fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. const int MAXN = 1e5 + 7;
  5. ll f[MAXN], n ,m, ans;
  6. vector <int> a[MAXN];
  7. bool mark[MAXN];
  8. void dfs(int u, int p){
  9. mark[u] = 1;
  10. for(auto v : a[u]){
  11. if(!mark[v]) dfs(v, u);
  12. if(v != p) f[u] = max(f[u], f[v] + 1);
  13. }
  14. }
  15.  
  16. int main(){
  17. ios_base::sync_with_stdio(0);
  18. cout.tie(0);
  19. cin.tie(0);
  20. cin >> n >> m;
  21. for(int i = 1; i <= m; i++){
  22. int x, y;
  23. cin >> x >> y;
  24. a[x].push_back(y);
  25. a[y].push_back(x);
  26. }
  27. dfs(1, -1);
  28. for(int i = 1; i <= n; i++) ans = max(ans, f[i]);
  29. cout << ans;
  30. }
Success #stdin #stdout 0.01s 6348KB
stdin
Standard input is empty
stdout
Standard output is empty