2.图论

图论1(最短路,最小生成树,差分约束,LCA)

开题顺序: \(DQE\)

\(A\) [ABC077D] Small Multiple

\(B\) [ABC216G] 01Sequence

\(C\) luogu P2662 牛场围栏

\(D\) luogu P2680 [NOIP2015 提高组] 运输计划

  • 题解
  • 代码写得有点难看,抽空重写一份。

\(E\) luogu P4211 [LNOI2014] LCA

\(F\) luogu P1852 跳跳棋

\(G\) luogu P10652 「ROI 2017 Day 1」前往大都会

\(H\) CF1005F Berland and the Shortest Paths

\(I\) CF507E Breaking Good

\(J\) CF1981E Turtle and Intersected Segments

\(K\) CF125E MST Company

\(L\) CF1707C DFS Trees

\(M\) CF1051F The Shortest Statement

\(N\) 「JOISC 2015 Day 1」卡片占卜

\(O\) [AGC016D] XOR Replace

\(P\) [AGC004D] Teleporter

\(Q\) SP116 INTERVAL - Intervals

  • 多倍经验: luogu P1645 序列 | luogu P1250 种树 | luogu P1986 元旦晚会 | UVA1723 Intervals | luogu P10934 西瓜种植

  • 题解

    点击查看代码
    struct node
    {
    	int nxt,to,w;
    }e[500001];
    int head[500001],vis[500001],dis[500001],cnt=0;
    void add(int u,int v,int w)
    {
    	cnt++;
    	e[cnt].nxt=head[u];
    	e[cnt].to=v;
    	e[cnt].w=w;
    	head[u]=cnt;
    }
    void spfa(int s)
    {
    	int i,x;
    	memset(vis,0,sizeof(vis));
    	memset(dis,-0x3f,sizeof(dis));
    	queue<int>q;
    	q.push(s);
    	dis[s]=0;
    	vis[s]=1;
    	while(q.empty()==0)
    	{
    		x=q.front();
    		for(i=head[x];i!=0;i=e[i].nxt)
    		{
    			if(dis[e[i].to]<dis[x]+e[i].w)
    			{
    				dis[e[i].to]=dis[x]+e[i].w;
    				if(vis[e[i].to]==0)
    				{
    					q.push(e[i].to);
    					vis[e[i].to]=1;
    				}
    			}
    		}
    		vis[x]=0;
    		q.pop();
    	}
    }
    int main()
    {
    	int n,r=0,u,v,w,i,t,j;
    	cin>>t;
    	for(j=1;j<=t;j++)
    	{
    		cin>>n;
    		r=cnt=0;
    		memset(e,0,sizeof(e));
    		memset(head,0,sizeof(head));
    		for(i=1;i<=n;i++)
    		{
    			cin>>u>>v>>w;
    			add(u,v+1,w);
    			r=max(r,v+1);
    		}
    		for(i=1;i<=r;i++)
    		{
    			add(i-1,i,0);
    			add(i,i-1,-1);
    		}
    		spfa(0);
    		cout<<dis[r]<<endl;
    		if(j!=t)
    		{
    			cout<<endl;
    		}
    	}
    	return 0;
    }
    

图论2(tarjan,2-SAT,欧拉路,竞赛图,图的性质,综合应用)

开题顺序: \(ABF\)

\(A\) luogu P8435 【模板】点双连通分量

\(B\) luogu P7771 【模板】欧拉路径

\(C\) luogu P4171 [JSOI2010] 满汉全席

\(D\) CF521E Cycling City

\(E\) CF1916F Group Division

\(F\) CF573B Bear and Blocks

  • 观察到第 \(i\) 次操作对第 \(j\) 根柱子的影响为 \(h_{i,j}=\min(h_{i-1,j}-1,h_{i-1,j-1},h_{i-1,j+1})\)

  • \(f_{i}\) 表示第 \(i\) 根柱子被摧毁的时间,类似地,状态转移方程为 \(f_{i}=\min(f_{i-1}+1,h_{i},f_{i+1}+1)\)

  • 转移过程实际上是分别以 \(0,n+1\) 为起点跑最短路,所以正反各更新一遍即可。

  • 最终有 \(\max\limits_{i=1}^{n} \{ f_{i} \}\) 即为所求。

    点击查看代码
    ll h[100010],f[100010];
    int main()
    {
    	ll n,ans=0,i;
    	cin>>n;
    	for(i=1;i<=n;i++)
    	{
    		cin>>h[i];
    		f[i]=min(f[i-1]+1,h[i]);
    	}
    	for(i=n;i>=1;i--)
    	{
    		f[i]=min(f[i+1]+1,f[i]);
    	}
    	for(i=1;i<=n;i++)
    	{
    		ans=max(ans,f[i]);
    	}
    	cout<<ans<<endl;
    	return 0;
    }
    

\(G\) CF1779E Anya's Simultaneous Exhibition

\(H\) CF1864G Magic Square

\(I\) CF1819E Roads in E City

\(J\) CF1919F2 Wine Factory (Hard Version)

图论3(二分图、网络流等)

\(A\) luogu P4382 [八省联考 2018] 劈配

\(B\) luogu P2469 [SDOI2010] 星际竞速

\(C\) luogu P9167 [省选联考 2023] 城市建造

\(D\) CF708D Incorrect Flow

\(E\) CF1250K Projectors

\(F\) luogu P2050 [NOI2012] 美食节

\(G\) CF1163F Indecisive Taxi Fee

\(H\) CF1773J Jumbled Trees

\(I\) UOJ 461. 新年的Dog划分

\(J\) luogu P10062 [SNOI2024] 拉丁方

\(K\) UOJ 592. 新年的聚会

\(L\) luogu P7214 [JOISC2020] 治療計画

posted @ 2024-10-05 07:12  hzoi_Shadow  阅读(31)  评论(1编辑  收藏  举报
扩大
缩小