1801. Reading books
来源:互联网 发布:南充广电网络收费标准 编辑:程序博客网 时间:2024/06/10 19:37
//use the method of dividing the books into several subsets
//color the similar books with the same color unless it has been colored
//then read the book with the least time in each subset first
#include <iostream>#include <cstring>#include <set>using namespace std;struct Node{public: int rank; int t; Node(int i,int j):rank(i),t(j){} bool operator <(const Node &node)const{ t < node.t; }};set<int> s[100];int color[100];void color_set(int k,int c){ if (color[k]!=-1) return; color[k] = c; for(set<int>::iterator it=s[k].begin(); it!=s[k].end(); it++) color_set(*it,c);}int main(){ int n,m; while( cin>>n>>m && n ){ int t[100]; memset(color,-1,sizeof(color)); for(int i=0; i<n; i++){ cin>>t[i]; s[i].clear(); s[i].insert(i); } for(int i=0; i<m; i++){ int a,b; cin>>a>>b; s[a].insert(b); s[b].insert(a); } for(int i=0; i<n; i++) color_set(i,i); int sum = 0; for(int i=0; i<n; i++){ set<int> tmp; for(int j=0; j<n; j++) if (color[j]==i) tmp.insert(t[j]); if (tmp.empty()) continue; sum += *tmp.begin(); tmp.erase(tmp.begin()); for(set<int>::iterator it=tmp.begin(); it!=tmp.end(); it++) sum += (*it)/2; } cout<<sum<<endl; } return 0;}
- 1801. Reading books
- soj 1801. Reading books
- Sicily 1801. Reading books
- Reading Books
- Reading books
- Reading Good Books
- About reading books
- reading books not technology
- SZU:B36 Reading books
- Problem B Reading books
- The Plan Of Reading Books
- GDCPC 2008:B Reading books
- Essential reading: My top 10 books (zz)
- ZZULI 1497 Reading Books
- The books which are worth reading for me
- Some Comments on Reading Some Books on CS(1)
- books
- books
- objective-c学习心得
- static作用
- audio format
- Source In Singht
- 八数码问题(HDU 1043)
- 1801. Reading books
- java基础---->jdbc数据库操作
- Linux 操作系统安装盘的定制
- [Linux/ Fedora17 64位 ]Chrome 安装flash
- ADO访问Excel 2007
- php中$this在普通方法和static方法下的差别
- How to attach JDK source code in Eclipse?
- KSQL查看表结构等
- c3p0配置及其属性