标签:ons \n str ems ++ ble org target mat
确认过眼神, 是二分图匹配板子题啦!!!
跑个匈牙利, 有匹配的输出, 记得先输出外籍飞行员, 因为有spj顺序无所谓啦qwq
最近A的最顺利的题了哈哈哈哈哈哈开心!!!!!!!!
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 const int sz = 100010; 6 int n, m, num = 0, ans = 0; 7 int head[sz], match[sz]; 8 bool vis[sz]; 9 struct edge { 10 int nxt, to; 11 }e[sz << 1]; 12 void add(int from, int to) { 13 e[++num].nxt = head[from]; 14 e[num].to = to; 15 head[from] = num; 16 } 17 bool dfs(int u) { 18 for(int i = head[u]; i; i = e[i].nxt) { 19 int v = e[i].to; 20 if(!vis[v]) { 21 vis[v] = 1; 22 if(!match[v] || dfs(match[v])) { 23 match[v] = u; 24 return true; 25 } 26 } 27 } 28 return false; 29 } 30 int main() { 31 scanf("%d%d", &n, &m); 32 while(1) { 33 int u, v; 34 scanf("%d%d", &u, &v); 35 if(u == -1 && v == -1) break; 36 add(u, v); 37 } 38 for(int i = 1; i <= n; i++) { 39 memset(vis, 0, sizeof(vis)); 40 if(dfs(i)) ans++; 41 } 42 printf("%d\n", ans); 43 for(int i = 1; i <= m; i++) 44 if(match[i]) printf("%d %d\n", match[i], i); 45 return 0; 46 }
标签:ons \n str ems ++ ble org target mat
原文地址:https://www.cnblogs.com/Hwjia/p/9898505.html