1119 - } } while(!unvisit.empty()){ subnum ++;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<iostream> #include<map> #include<vector> #include<set> using namespace std; map<int, vector<int> > edge; set<int> unvisit; int failnode; void travel(int n){ if(n == failnode) return; if(unvisit.find(n) == unvisit.end()) return; unvisit.erase(n); vector<int> &v = edge[n]; int i; for(i=0;i<v.size();i++){ travel(v[i]); } } void fun(){ map<int,int> spf; map<int, vector<int> >::iterator iter; vector<int> node; for(iter= edge.begin(); iter!= edge.end(); iter++){ node.push_back(iter->first); } int i,j; int subnum; for(i=0;i<node.size();i++){ failnode = node[i]; unvisit.clear(); subnum = 0; for(j=0;j<node.size();j++){ if(i!=j){ unvisit.insert(node[j]);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } } while(!unvisit.empty()){ subnum ++; travel(*(unvisit.begin())); } if(subnum &gt; 1){ spf[failnode] = subnum; } } if(spf.size() == 0){ cout&lt;&lt;&quot; No SPF nodes&quot;&lt;&lt;endl; return; } map&lt;int,int&gt;::iterator link; for(link = spf.begin(); link != spf.end(); link++){ cout&lt;&lt;&quot; SPF node &quot;&lt;&lt;link-&gt;first&lt;&lt;&quot; leaves &quot; &lt;&lt;link-&gt;second &lt;&lt;&quot; subnets&quot;&lt;&lt;endl; } } int main(){ int tstcase = 0; int a,b; cin&gt;&gt;a; while(a != 0){ if(tstcase) cout&lt;&lt;endl; edge.clear(); while(a!=0){ cin&gt;&gt;b; edge[a].push_back(b); edge[b].push_back(a); cin&gt;&gt;a; } cout&lt;&lt;&quot;Network #&quot;&lt;&lt;++tstcase&lt;&lt;endl; fun(); cin&gt;&gt;a; } return 0; }...
View Full Document

Page1 / 2

1119 - } } while(!unvisit.empty()){ subnum ++;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online