HeRaNO's NOIP CSP Round Day 2 T2 PESTC
对于我这种菜鸡来说还是挺有迷惑性的。
在考场发现答案问的是跟最值有关的数量,想到二分,结果果然具有单调性,考虑二份答案+验证
其实什么反转什么的,可以不用去管他,对于长度小于二分答案mid的道路,不去考虑
只要是在图中出现了环,就一定不行
所以这道题变成了判环的问题,tarjan和dfs均可
AC code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | #include<bits/stdc++.h> #define re register #define inc(i,j,k) for(re int i=j;i<=k;++i) #define dec(i,j,k) for(re int i=j;i>=k;--i) #define ra(i,u) for(re int i=head[u];i;i=e[i].nxt) using namespace std; const int maxn=200010; const int maxm=300010; inline int read() { re int x=0,f=1; char ch=getchar(); while (ch< '0' ||ch> '9' ) { if (ch== '-' ) f=-1; ch=getchar();} while (ch>= '0' &&ch<= '9' ) {x=x*10+(ch^48); ch=getchar();} return x*f; } int head[maxn],dfn[maxn],low[maxn],sta[maxn],scc[maxn],tong[maxn]; int cnt,n,m,tot,top,maxx=-1,num; bool vis[maxn]; struct node { int to,nxt,w; }e[maxm]; inline void add( int u, int v, int w) { e[++cnt].to=v; e[cnt].nxt=head[u]; e[cnt].w=w; head[u]=cnt; } bool flag=0; inline void tarjan( int x, int k) { dfn[x]=low[x]=++tot; sta[++top]=x; ra(i,x) { if (e[i].w<=k) continue ; re int v=e[i].to; if (!dfn[v]) { tarjan(v,k); low[x]=min(low[x],low[v]); } else if (!scc[v]) low[x]=min(low[x],dfn[v]); } if (low[x]==dfn[x]) { scc[x]=++num; ++tong[num]; while (sta[top]!=x) { scc[sta[top--]]=num; ++tong[num]; /*if(tong[num]>=2) { flag=1; return; }*/ } --top; } } inline void clear() { inc(i,1,n) { dfn[i]=low[i]=sta[i]=scc[i]=0; vis[i]=0; } memset(tong,0, sizeof (tong)); tot=0; top=0; num=0; return ; } inline bool check( int x) { clear(); // flag=0; inc(i,1,n) { if (!dfn[i]) { tarjan(i,x); // cout<<"QAQ"<<endl; // if(flag==1) return 0; } } inc(i,1,num) { if (tong[i]>=2) return 0; } return 1; } int main() { // freopen("test6.in","r",stdin); int l=0,r=2e9,ans=2e9; n=read(); m=read(); re int xx,yy,zz; inc(i,1,m) { xx=read(); yy=read(); zz=read(); add(xx,yy,zz); maxx=max(maxx,zz); } l=0,r=maxx,ans=maxx; while (l<=r) { re int mid=(l+r)>>1; // cout<<mid<<endl; if (check(mid)) ans=mid,r=mid-1; else l=mid+1; // cout<<ans<<endl; } cout<<ans<<endl; } |
我居然最开始数组开小了。。。 这就是考试睡觉的下场,写的代码前后断片。。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了