1085 - t += save; if(t > 1) return 0; if(save ){...

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

View Full Document Right Arrow Icon
#include<iostream> #include<map> using namespace std; map<int,int> visit; map<int,int> tree; multimap<int,int> edge; int nodenum,place; char buffer[256]; int calc(int node){ int value = 0; int t; if(node == place) return 1; if(visit.find(node) != visit.end()) return 0; visit[node] = 0; multimap<int,int>::iterator first,last; first = edge.lower_bound(node); last = edge.upper_bound(node); for(;first!=last; first++){ t = calc(first->second); value += t; if(t == 1){ tree[node] = first->second; } } visit[node] = value; return value >0; } int fun(){ int t = 0; int save; multimap<int,int>::iterator first,last; first = edge.lower_bound(0); last = edge.upper_bound(0); visit[0] = 0; for(;first!=last;first++){ save = calc(first->second);
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: t += save; if(t &gt; 1) return 0; if(save ){ tree[0] = first-&gt;second; } } visit[0] = t; save = t = 0; while(visit[t] == 1){ save = t; t = tree[t]; } if(visit[t] == 0) return save; return t; } int main(){ int blocknum; int fro, to; char tmp,ch; cin&gt;&gt;blocknum; //blocknum = 1; while(blocknum --){ visit.clear(); tree.clear(); edge.clear(); cin&gt;&gt;nodenum&gt;&gt;place; cin.getline(buffer,256); cin.getline(buffer,256); while(buffer[0] != 0){ sscanf(buffer,&quot;%d%d&quot;,&amp;fro,&amp;to); edge.insert(make_pair(fro,to)); cin.getline(buffer,256); } place = fun(); cout&lt;&lt;&quot;Put guards in room &quot;&lt;&lt;place&lt;&lt;&quot;.\n&quot;; if(blocknum) cout&lt;&lt;(&quot;\n&quot;); } 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

1085 - t += save; if(t &amp;amp;gt; 1) return 0; if(save ){...

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