CodeForces - 645D Robot Rapping Results Report
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 645D Robot Rapping Results Report相关的知识,希望对你有一定的参考价值。
?????????target repo ?????? inline sizeof efi class return ORC
??????????????????????????????????????????????????????????????????????????????????????????????????????check??????????????????
#include<bits/stdc++.h> #define ll long long using namespace std; const int N=1e5+5; int hd[N],to[N],ne[N],num,n,m; int d[N],ans=-1,mid; inline void add(int x,int y){ to[++num]=y,ne[num]=hd[x],hd[x]=num;} inline bool check(){ memset(d,0,sizeof(d)); int x=0,y; for(int i=1;i<=mid;i++) d[to[i]]++; for(int i=1;i<=n;i++) if(!d[i]) if(!x) x=i; else return 0; for(;x;){ y=x,x=0; for(int i=hd[y];i;i=ne[i]) if(i<=mid&&!(--d[to[i]])) if(!x) x=to[i]; else return 0; } return 1; } int main(){ scanf("%d%d",&n,&m); for(int i=1,uu,vv;i<=m;i++) scanf("%d%d",&uu,&vv),add(uu,vv); int l=1,r=m; while(l<=r){ mid=l+r>>1; if(check()) ans=mid,r=mid-1; else l=mid+1; } printf("%d ",ans); return 0; }
以上是关于CodeForces - 645D Robot Rapping Results Report的主要内容,如果未能解决你的问题,请参考以下文章
CodeForces - 645D Robot Rapping Results Report
CodeForces 645D Robot Rapping Results Report
Codeforces 589J Cleaner Robot(DFS)
CodeForces 626A Robot Sequence