• 「CF852D」Exploration Plan


    题目描述

    给定一张 (V) 个点,(M) 条边的边带权无向图,有 (N) 个人分布在图上的点上,第 (i) 个人在 (x_i) 这个点上,定义从一个点走到另一个点的时间为所走的路径上所有边权之和,问至少过多久才可以满足至少有 (K) 个点上有人。

    数据范围:
    (1le V le600,1le E le 20000,1le N lemin(V,200),1le K le N)

    基本思路

    首先可以二分答案。
    对于当前二分到的 (mid),我们对于每一个人,都向他可以去到的点连一条边(路径的最短距离可以用 ( ext{Floyd}) 预处理一下),然后直接跑二分图最大匹配就好了。

    细节注意事项

    • 记得判无解

    参考代码

    /*--------------------------------
      Author: The Ace Bee
      Blog: www.cnblogs.com/zsbzsb
      This code is made by The Ace Bee
    --------------------------------*/
    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cstdio>
    #include <cctype>
    #include <cmath>
    #include <ctime>
    #include <queue>
    #define rg register
    using namespace std;
    template < typename T > inline void read(T& s) {
    	s = 0; int f = 0; char c = getchar();
    	while (!isdigit(c)) f |= (c == '-'), c = getchar();
    	while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
    	s = f ? -s : s;
    }
    
    const int _ = 700;
    const int INF = 2147483647;
    
    int n, m, p, k, x[_];
    int dis[_][_], vis[_], bel[_], g[_][_];
    
    inline int dfs(int u) {
    	for (rg int i = 1; i <= n; ++i) {
    		if (vis[i] || !g[u][i]) continue;
    		vis[i] = 1;
    		if (bel[i] == 0 || dfs(bel[i]))
    			return bel[i] = u, 1;
    	}
    	return 0;
    }
    
    inline bool check(int mid) {
    	memset(g, 0, sizeof g);
    	for (rg int i = 1; i <= p; ++i)
    		for (rg int j = 1; j <= n; ++j)
    			g[i][j] = (int) dis[x[i]][j] <= mid;
    	int res = 0;
    	memset(bel, 0, sizeof bel);
    	for (rg int i = 1; i <= p; ++i)
    		memset(vis, 0, sizeof vis), res += dfs(i);
    	return res >= k;
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
    	freopen("in.in", "r", stdin);
    #endif
    	read(n), read(m), read(p), read(k);
    	for (rg int i = 1; i <= p; ++i) read(x[i]);
    	for (rg int i = 1; i <= n; ++i)
    		for (rg int j = 1; j <= n; ++j)
    			dis[i][j] = 1e9;
    	for (rg int i = 1; i <= n; ++i) dis[i][i] = 0;
    	for (rg int u, v, d, i = 1; i <= m; ++i) {
    		read(u), read(v), read(d);
    		dis[v][u] = dis[u][v] = min(dis[u][v], d);
    	}
    	for (rg int k = 1; k <= n; ++k)
    		for (rg int i = 1; i <= n; ++i)
    			for (rg int j = 1; j <= n; ++j)
    				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
    	int l = 0, r = 1731311 + 1;
    	while (l < r) {
    		int mid = (l + r) >> 1;
    		if (check(mid)) r = mid;
    		else l = mid + 1;
    	}
    	if (l > 1731311) puts("-1");
    	else printf("%d
    ", l);
    	return 0;
    }
    

    完结撒花 (qwq)

  • 相关阅读:
    jackson学习之一:基本信息 jackson学习之二:jackson-core
    FastAPI项目实战:SayHello(FastAPI + vue.js + axios + element ui 翻自Flask版
    MarkDown优雅发表
    docker使用笔记
    JVM的重要性 从上层应用程序到底层操作系统,到底有哪些东西?
    Python正则表达式re模块和os模块实现文件搜索模式匹配
    区块链学习6:图灵完备和图灵不完备
    moviepy音视频开发:使用credits1给视频加片头片尾字幕
    moviepy音视频开发:使用volumex调节音量大小及其花式用法
    moviepy音视频开发:audio_normalize调整剪辑音量大小到正常
  • 原文地址:https://www.cnblogs.com/zsbzsb/p/11684039.html
Copyright © 2020-2023  润新知