路徑判斷 可用dfs floyed 並查集

2021-09-23 14:27:50 字數 952 閱讀 2782

7-1 路徑判斷 (20 分)

給定乙個有n個頂點和e條邊的無向圖,請判斷給定的兩個頂點之間是否有路徑存在。 假設頂點從0到n−1編號。

輸入第1行給出2個整數n(0隨後e行,每行給出一條邊的兩個端點。每行中的數字之間用1空格分隔。

最後一行給出兩個頂點編號i,j(0≤i,j如果i和j之間存在路徑,則輸出"there is a path between i and j.",

否則輸出"there is no path between i and j."。

7 6

0 12 3

1 40 2

1 35 6

0 3

there is a path between 0 and 3.
7 6

0 12 3

1 40 2

1 35 6

0 6

there is no path between 0 and 6.
//法1:圖的基本操作(dfs)

#include

int vis[15];

int p,q,flag=0;

typedef struct graph

graph;

void dfs(graph g,int p)

}int getroot(int a)

else

}void mergeit(int x,int y)

else

}int main()

int p,q;

scanf("%d%d",&p,&q);

if(n==1)

else if(getroot(p)==getroot(q))//判斷p,q兩點的根節點是否相同,如果根節點相同,則這兩點間有路徑

else

}

判斷網路是否可用

這段 用於判斷網路是否可用,如果不可用則開啟網路設定,設定網路連線,當然也可以忽略設定,即不做處理。connectivitymanager connectmanager connectivitymanager this.getsystemservice connectivity service if...

判斷webservice是否可用

在.net中驗證webservice的url有效並且驗證服務可用 需要用到win32下的元件,比如microsoft xml,v5.0測試程式具體如下 建乙個專案,在你的引用中新增com 找到microsoft xml,v5.0然後using msxml2 該元件提供乙個介面msxml2.xmlht...

判斷當前網路是否可用

有兩種方式 方式一,是否有網路 所有網路 mobile wifi public boolean isnetworkconnected 第二種方式,是否有指定的網路 檢查wifi是否可用的兩種方式 wifimanager wifimanager wifimanager getsystemservice...