标签:des style blog http color java os io
4 A B C D 5 laptop B phone C pager B clock B comb X 3 B X X A X D
1
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <map> 13 #include <stack> 14 #define LL long long 15 #define pii pair<int,int> 16 #define INF 0x3f3f3f3f 17 using namespace std; 18 const int maxn = 510; 19 map<string,int>mp; 20 queue<int>q; 21 int n,m,k,c[maxn][maxn] = {0},S,T,p[maxn],maxFlow = 0; 22 void bfs() { 23 while(true) { 24 memset(p,-1,sizeof(p)); 25 while(!q.empty()) q.pop(); 26 q.push(S); 27 while(!q.empty()) { 28 int u = q.front(); 29 q.pop(); 30 for(int i = 0; i <= T; i++) { 31 if(p[i] == -1 && c[u][i] != 0) { 32 p[i] = u; 33 q.push(i); 34 } 35 } 36 if(p[T] != -1) break; 37 } 38 if(p[T] == -1) break; 39 for(int u = T; u != S; u = p[u]) { 40 c[p[u]][u] -= 1; 41 c[u][p[u]] += 1; 42 } 43 maxFlow += 1; 44 } 45 } 46 int main() { 47 string plug,plug2,device; 48 int i,t; 49 cin>>n; 50 for(i = 1; i <= n; i++) { 51 cin>>plug; 52 mp[plug] = i; 53 } 54 t = n; 55 cin>>m; 56 for(i = 1; i <= m; i++) { 57 cin>>device>>plug; 58 if(mp.find(plug) == mp.end()) mp[plug] = ++t; 59 c[i][m+mp[plug]] = 1; 60 } 61 cin>>k; 62 for(i = 1; i <= k; i++) { 63 cin>>plug>>plug2; 64 if(mp.find(plug) == mp.end()) mp[plug] = ++t; 65 if(mp.find(plug2) == mp.end()) mp[plug2] = ++t; 66 c[m+mp[plug]][m+mp[plug2]] = INF; 67 } 68 S = 0; 69 T = m+t+1; 70 for(int i = 1; i <= m; i++) c[S][i] = 1; 71 for(int i = 1; i <= n; i++) c[m+i][T] = 1; 72 bfs(); 73 printf("%d\n",m-maxFlow); 74 return 0; 75 }
BNUOJ 1206 A Plug for UNIX,布布扣,bubuko.com
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/crackpotisback/p/3916985.html