zoukankan      html  css  js  c++  java
  • Codeforces 1139E(二分图最大匹配)

    pi只有0~5000且只找最小的没出现的,又要找不同club的,考虑二分匹配,左边pi,右边ci,一个匹配一个。离线倒着加边即可。

    const int maxn = 5e3 + 5;
    int m, n, d, now;
    int P[maxn], C[maxn], K[maxn];
    int match[maxn], ans[maxn];
    bool mark[maxn], used[maxn];
    vector<int> G[maxn];
    
    bool dfs(int cur) {
    	if (used[cur])	return false;
    	used[cur] = 1;
    	for (auto to : G[cur]) {
    		if (match[to] == -1 || dfs(match[to])) {
    			match[to] = cur;
    			return true;
    		}
    	}
    	return false;
    }
    
    int main() {
    	read(m), read(n);
    	rep(i, 1, m)	read(P[i]);
    	rep(i, 1, m)	read(C[i]);
    	read(d);
    	rep(i, 1, d) {
    		read(K[i]);
    		mark[K[i]] = true;
    	}
    	rep(i, 1, m) {
    		if (!mark[i]) {
    			G[P[i]].push_back(C[i]);
    		}
    	}
    
    	init(match, -1);
    	irep(i, d, 1) {
    		init(used, 0);
    		while (dfs(now)) {
    			now++;
    			init(used, 0);
    		}
    
    		ans[i] = now;
    		int t = K[i];
    		G[P[t]].push_back(C[t]);
    	}
    
    	rep(i, 1, d)	writeln(ans[i]);
    	return 0;
    }
    
  • 相关阅读:
    SpringBoot JdbcTemplate多数据源
    SpringBoot Mybatis多数据源
    SpringBoot 配置文件2
    SpringBoot 配置文件1
    SpringBoot 日志配置
    乌镇行
    防火墙
    PL/SQL查询结果窗口太小且显示不完全
    python 列表解析
    HTML
  • 原文地址:https://www.cnblogs.com/AlphaWA/p/10676659.html
Copyright © 2011-2022 走看看