【YBTOJ】最大半连通子图

在这里插入图片描述

题意:

半连通图:任意两个点之间有一条路(不一定两两互相到达)

思路:

分析一波,发现最大的半连通子图一定是一条链,因为如果有一个旁生出的点,那么这个点一定有一些点是到达不了的(自己举例试一试)
首先,tarjan缩点
然后我们先用排序把边去重
这时设一个f[i]表示到第i的最长路径是多少,ans[i]表示到第i个点的最长路径有多少条
然后直接拓扑DP

c o d e code code

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>

using namespace std;

int n, m, p, cnt, top, tmp;
int head[2000010], tot;
struct node
{
   
	int from, to, next;
}b[2000010];
struct abc
{
   
	int x, y;
}a[2000010];
int head1[2000010], tot1;
node e[2000010];
int ru[2000010], ans[2000010], f[2000010];
int c[2000010], stack[2000010], low[2000010], dfn[2000010], d[2000010];
bool v[2000010];

inline void add(register int x, register int y)
{
   
	b[++tot]=(node){
   x, y
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值