加邊 ssl 2630 強連通分量(縮點)

2021-07-30 03:11:02 字數 1513 閱讀 6529

給出乙個大小為n × m (1 ≤ n, m ≤ 300)的矩形,矩形的每個位置有乙個高度 h (1 ≤ h ≤ 1,000,000)。在相鄰的格點間,你可以上下或者左右移動。但是你只能從高的格點走向不比它高的格點。相同高度的格點間兩個方向都能移動。

現在,你需要計算出至少需要新增多少條雙向邊才能使到矩陣任意兩點之間都可以互相。

根據規則建圖後縮點,統計各個點的入度和出度。

再分別統計入度和出度為零的點的數量,輸出較大的那個。

#include

#include

#include

#include

#include

#include

#include

using

namespace

std;

struct arredge[1000000];

int ls[100000];

int edge_m=0;

int n,m;

void add(int x,int y)

,ls[x]=edge_m;

return;

}int v[100000];

int dfn[100000];

int low[100000];

int scc[100000];

int ans=0;

int num=0;

stack

sta;

void tarjan(int x)

else

if (v[y]) low[x]=min(dfn[y],low[x]);

}if (dfn[x]==low[x])

int y=sta.top();

v[y]=0;

scc[y]=ans;

sta.pop();

}} int a[400][400];

int sx(int x,int y)

int chu[100000];

int ru[100000];

int main()

for (int i=1;i<=n*m;i++)

if (scc[i]==0)

tarjan(i);

for (int i=1;i<=edge_m;i++)

if (scc[edge[i].x]!=scc[edge[i].y])

int anss=0;

for (int i=1;i<=ans;i++)

if (chu[i]==0)

anss++;

int ansss=0;

for (int i=1;i<=ans;i++)

if (ru[i]==0)

ansss++;

anss=max(anss,ansss);

if (ans==1)

anss=0;

printf("%d",anss);

fclose(stdin);

fclose(stdout);

}

演算法 強連通分量縮點

有時對於乙個有向圖我們及其渴望將其變為乙個有向無環圖,這樣我們就要用到強連通分量縮點了。洛谷3387 縮點 題目背景 縮點 dp。題目描述 給定乙個 n個點 m條邊有向圖,每個點有乙個權值,求一條路徑,使路徑經過的點權值之和最大。你只需要求出這個權值和。允許多次經過一條邊或者乙個點,但是,重複經過的...

點連通分量 邊連通分量 割點和橋 強連通分量

老是搞不清他們的關係,不知道該用那份 今天理了一下,整理一下模板 點連通分量 可以求出點連通分量包含哪些點,那個點屬於那個連通分量 struct edge int pre maxn iscut maxn bccno maxn dfs clock,bcc cnt vectorg maxn bcc ma...

強連通分量縮點的模板

include include include include using namespace std define inti a memset a,0,sizeof a define min a,b a b b a define max a,b a b a b const int max 1605...