日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

2013年第四届蓝桥杯C/C++ A组国赛 —— 第五题:网络寻路

發(fā)布時間:2024/5/6 c/c++ 59 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2013年第四届蓝桥杯C/C++ A组国赛 —— 第五题:网络寻路 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

標題:網(wǎng)絡尋路

X 國的一個網(wǎng)絡使用若干條線路連接若干個節(jié)點。節(jié)點間的通信是雙向的。某重要數(shù)據(jù)包,為了安全起見,必須恰好被轉發(fā)兩次到達目的地。該包可能在任意一個節(jié)點產(chǎn)生,我們需要知道該網(wǎng)絡中一共有多少種不同的轉發(fā)路徑。

源地址和目標地址可以相同,但中間節(jié)點必須不同。

如圖1所示的網(wǎng)絡。

1 -> 2 -> 3 -> 1 是允許的

1 -> 2 -> 1-> 2 或者 1->2->3->2 都是非法的。

輸入數(shù)據(jù)的第一行為兩個整數(shù)N M,分別表示節(jié)點個數(shù)和連接線路的條數(shù)(1<=N<=10000; 0<=M<=100000)。
接下去有M行,每行為兩個整數(shù) u 和 v,表示節(jié)點u 和 v 聯(lián)通(1<=u,v<=N , u!=v)。

輸入數(shù)據(jù)保證任意兩點最多只有一條邊連接,并且沒有自己連自己的邊,即不存在重邊和自環(huán)。

輸出一個整數(shù),表示滿足要求的路徑條數(shù)。

例如:
用戶輸入:
3 3
1 2
2 3
1 3
則程序應該輸出:
6

再例如:
用戶輸入:
4 4
1 2
2 3
3 1
1 4
則程序應該輸出:
10

資源約定:
峰值內(nèi)存消耗 < 64M
CPU消耗 < 1000ms

請嚴格按要求輸出,不要畫蛇添足地打印類似:“請您輸入…” 的多余內(nèi)容。

所有代碼放在同一個源文件中,調(diào)試通過后,拷貝提交該源碼。

注意: main函數(shù)需要返回0
注意: 只使用ANSI C/ANSI C++ 標準,不要調(diào)用依賴于編譯環(huán)境或操作系統(tǒng)的特殊函數(shù)。
注意: 所有依賴的函數(shù)必須明確地在源文件中 #include , 不能通過工程設置而省略常用頭文件。

提交時,注意選擇所期望的編譯器類型(千萬不要混淆c和cpp)。

Code

/*^....0^ .1 ^1^.. 011.^ 1.0^ 1 ^ ^0.11 ^ ^..^0. ^ 0^.0 1 .^.1 ^0 .........001^.1 1. .111100....01^00 11^ ^1. .1^1.^ ^0 0^.^ ^0..1.1 1..^1 .0 ^ ^00. ^^0.^^ 0 ^^110.^0 0 ^ ^^^10.01^^ 10 1 1 ^^^1110.101 10 1.1 ^^^1111110010 01 ^^ ^^^1111^1.^ ^^^10 10^ 0^ 1 ^^111^^^0.1^ 1....^11 0 ^^11^^^ 0.. ....1^ ^ ^1. 0^ ^11^^^ ^ 1 111^ ^ 0.10 00 11 ^^^^^ 1 0 1.0^ ^0 ^0 ^^^^ 0 0.0^ 1.0 .^ ^^^^ 1 1 .0^.^ ^^ 0^ ^1 ^^^^ 0. ^.11 ^ 11 1. ^^^ ^ ^ ..^^..^ ^1 ^.^ ^^^ .0 ^.00..^ ^0 01 ^^^ .. 0..^1 .. .1 ^.^ ^^^ 1 ^ ^0001^ 1. 00 0. ^^^ ^.0 ^.1. 0^. ^.^ ^.^ ^^^ ..0.01 .^^. .^ 1001 ^^ ^^^ . 1^. ^ ^. 11 0. 1 ^ ^^ 0.0 ^. 0 ^0 1 ^^^ 0.0.^ 1. 0^ 0 .1 ^^^ ...1 1. 00 . .1 ^^^ ..1 1. ^. 0 .^ ^^ ..0. 1. .^ . 0 ..1 1. 01 . . ^ 0^.^ 00 ^0 1. ^ 1 1.0 00 . ^^^^^^ ..^ 00 01 ..1. 00 10 1 ^^.1 00 ^. ^^^ .1.. 00 .1 1..01 ..1.1 00 1. ..^ 10^ 1^ 00 ^.1 0 1 1.1 00 00 ^ 1 ^. 00 ^.^ 10^ ^^1.1 00 00 10^..^ 1. ^. 1.0 1 ^. 00 00 .^^ ^. ^ 1 00 ^0000^ ^ 011 0 ^. 00.0^ ^00000 1.00.1 11. 1 0 1^^0.01 ^^^ 01.^ ^ 1 1^^ ^.^1 1 0... 1 ^1 1^ ^ .01 ^ 1.. 1.1 ^0.0^ 0 1..01^^100000..0^1 1 ^ 1 ^^1111^ ^^0 ^ ^ 1 1000^.1 ^.^ . 00.. 1.1 0. 01. . 1. .^1. 1 1. ^0^ . ^.1 00 01^.0 001. .^*/ // VB_king —— 2018_Finals_C_C++_3.cpp created by VB_KoKing on 2019-05-19:20. /* Procedural objectives:Variables required by the program:Procedural thinking:Functions required by the program:Determination algorithm:Determining data structure:*/ /* My dear Max said: "I like you, So the first bunch of sunshine I saw in the morning is you, The first gentle breeze that passed through my ear is you, The first star I see is also you. The world I see is all your shadow."FIGHTING FOR OUR FUTURE!!! */ #include <vector> #include <cstring> #include <iostream>#define maxn 10007using namespace std;int N,M; long long ans; bool vis[maxn]; vector <int> G[maxn];void dfs(int start,int step,int score){if(step==3){for(int i=0;i<G[start].size();i++){int v=G[start][i];if(!vis[v]||v==score)ans++;}return;} else {for(int i=0;i<G[start].size();i++){int v=G[start][i];if(!vis[v]){vis[v]=true;dfs(v,step+1,score);vis[v]=false;}}}return; }int main(){cin>>N>>M;memset(vis,0,sizeof(vis));for(int i=0;i<M;i++){int u,v;cin>>u>>v;G[u].push_back(v);G[v].push_back(u);}for(int i=1;i<N+1;i++){vis[i]=true;dfs(i,1,i);vis[i]=false;}cout<<ans<<endl;return 0; }

總結

以上是生活随笔為你收集整理的2013年第四届蓝桥杯C/C++ A组国赛 —— 第五题:网络寻路的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。