#include<bits/stdc++.h> #include<math.h> #include<map> #include<queue> #include<stack> #include<set> #include<map> #include<assert.h> #include <algorithm> #define ll long long #include <time.h> using namespace std; //clock_t Begin,End; //Begin = clock();printf("%dms\n",End-Begin); int father[1000005]; struct ss{     int next;     int to; }arr[1000005]; int tot; void add(int a,int b){     arr[tot].next=father[a];     arr[tot].to=b;     father[a]=tot++; } int vis[1000005]; int num[1000005]; set<int>se; int dfs(int t){     vis[t]=1;     int tt=-1;     for(int i=father[t];i!=-1;i=arr[i].next){         int to=arr[i].to;         if(vis[to]==0){             tt=max(tt,dfs(to));         }else{             tt=max(tt,num[to]);         }     }     if(tt==-1) return t;     else return num[t]=tt;     } int max(int a,int b){     return a>b?a:b;  } int main(){     int n;     scanf("%d",&n);     int a,b;     memset(father,-1,sizeof(father));     for(int i=0;i<n;i++){         scanf("%d %d",&a,&b);         se.insert(a);         if(a>b) swap(a,b);         add(a,b);     }     int sum=0;     for(set<int>::iterator ite=se.begin();ite!=se.end();ite++){         if(vis[*ite]==0){             dfs(*ite);             sum=max(sum,num[*ite]-*ite);         } //        printf("%d\n",num[*ite]);     }     printf("%d\n",sum);          return 0; }
点赞 评论

相关推荐

WhiteAlbum...:学院本2中大厂垂直实习➕acm比赛 秋招0面试
点赞 评论 收藏
分享
面了100年面试不知...:头像换成柯南再试试
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务