妈妈说如果昵称太长是会被 level
获赞
1
粉丝
1
关注
0
看过 TA
3
北京交通大学
2022
C++
IP属地:北京
啥啥啥
私信
关注
2019-03-16 17:32
北京交通大学 C++
为什么不能dfs搜索能去的点,过的代码都是cmp。。。。。。。 愁死我了
妈妈说如果昵称太长是会被:#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[2000005]; 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[2000005]; int num[2000005]; int se[1000005]; 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));     int r=0;     for(int i=0;i<n;i++){         scanf("%d %d",&a,&b);         se[++r]=a;         add(a,b);     }     int sum=0;     for(int i=1;i<=r;i++){         if(vis[se[i]]==0){             dfs(se[i]);             sum=max(sum,num[se[i]]-se[i]);         } //        printf("%d\n",num[*ite]);     }     printf("%d\n",sum);          return 0; } 出题人给的范围不够实际的数要比1000000大,要把数组开大, 数据过多导致set爆掉 dfs过了。
0 点赞 评论 收藏
分享

创作者周榜

更多
关注他的用户也关注了:
牛客网
牛客企业服务