国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

1013. Battle Over Cities (25)

2019-11-08 20:10:31
字體:
來源:轉載
供稿:網友
#include<iostream>#include<vector>using namespace std;vector<int> kkk;int N,M,K;int n;bool temp[1002];bool visited[1002];typedef struct ArcNode{ struct ArcNode *next; int adj;}ArcNode;//vector<ArcNode> arc;ArcNode arc[1000000];vector<ArcNode *> vexarc; typedef struct VNode{ int name; ArcNode *first;}VNode;typedef struct{ int arcnum,vexnum; VNode vs[1002];}LGraph;bool CreateLG(LGraph &G){ cin>>N>>M>>K; G.arcnum=M; G.vexnum=N; for(int t=0;t<G.vexnum;t++) { G.vs[t].name=t+1; G.vs[t].first=NULL; vexarc.push_back(G.vs[t].first); visited[t]=false; } for(int t=0;t<G.arcnum;t++) { int a,b; cin>>a>>b; arc[2*t].adj=a-1;arc[2*t].next=NULL; arc[2*t+1].adj=b-1;arc[2*t+1].next=NULL; // hu.adj=a-1;hu.next=NULL;arc.push_back(hu); // hu.adj=b-1;hu.next=NULL;arc.push_back(hu); if(G.vs[a-1].first==NULL) G.vs[a-1].first=vexarc[a-1]=&arc[2*t+1]; else vexarc[a-1]=vexarc[a-1]->next=&arc[2*t+1]; if(G.vs[b-1].first==NULL) G.vs[b-1].first=vexarc[b-1]=&arc[2*t]; else vexarc[b-1]=vexarc[b-1]->next=&arc[2*t]; } for(int t=0;t<K;t++) { int k; cin>>k; k--; kkk.push_back(k); //visited[k]=false; } return true;}bool bfs(LGraph &G,VNode f){ ArcNode *p=f.first; temp[f.name-1]=true; while(p!=NULL) { if(!temp[p->adj]) bfs(G,G.vs[p->adj]); p=p->next; } return true;}int main(){ LGraph G; CreateLG(G); for(vector<int>::iterator it=kkk.begin();it!=kkk.end();it++) { for(int t=0;t<G.vexnum;t++) temp[t]=visited[t]; temp[*it]=true; n=0; for(int t=0;t<G.vexnum;t++) {if(!temp[t]) {bfs(G,G.vs[t]);n++;}} if(n>0) cout<<n-1<<endl; else cout<<" "<<endl; } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 舟山市| 茂名市| 聊城市| 东乡族自治县| 福建省| 安塞县| 乐平市| 德保县| 玉环县| 保亭| 祁门县| 镇远县| 汝阳县| 伊川县| 松潘县| 班戈县| 霍城县| 南京市| 贡山| 滦平县| 邢台市| 特克斯县| 扶沟县| 潼关县| 剑川县| 尼玛县| 元谋县| 石狮市| 磐石市| 盐津县| 长海县| 万山特区| 巫溪县| 巴里| 比如县| 蒙自县| 巴彦淖尔市| 永福县| 南部县| 新和县| 玉林市|