1119 - while!unvisit.empty subnum travel(unvisit.begin...

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 > 1){ spf[failnode] = subnum; } } if(spf.size() == 0){ cout<<" No SPF nodes"<<endl; return; } map<int,int>::iterator link; for(link = spf.begin(); link != spf.end(); link++){ cout<<" SPF node "<<link->first<<" leaves " <<link->second <<" subnets"<<endl; } } int main(){ int tstcase = 0; int a,b; cin>>a; while(a != 0){ if(tstcase) cout<<endl; edge.clear(); while(a!=0){ cin>>b; edge[a].push_back(b); edge[b].push_back(a); cin>>a; } cout<<"Network #"<<++tstcase<<endl; fun(); cin>>a; } return 0; }...
View Full Document

This note was uploaded on 02/18/2010 for the course CS 100 taught by Professor Acm during the Spring '10 term at Zhejiang University.

Page1 / 2

1119 - while!unvisit.empty subnum travel(unvisit.begin...

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