CF546E Soldier and Traveling 题解】的更多相关文章

CF546E Soldier and Traveling 题目描述 In the country there are \(n\) cities and \(m\) bidirectional roads between them. Each city has an army. Army of the i-th city consists of \(a_{i}\) soldiers. Now soldiers roam. After roaming each soldier has to eith…
题目描述 In the country there are n n n cities and m m m bidirectional roads between them. Each city has an army. Army of the i i i -th city consists of ai a_{i} ai​ soldiers. Now soldiers roam. After roaming each soldier has to either stay in his city o…
题意 给定 n 个城市,m 条边.人只能从走相邻边相连(只能走一次)的城市. 现在给你初始城市的每一个人数,再给一组每个城市人数.询问是否可以从当前人数变换到给定人数.如果能,输入"YES"并输出方案,不能则输出"NO". http://codeforces.com/contest/546/problem/E 思路 当∑a!=∑b时,肯定不能. 建一个超级源点s和超级汇点t,s到(1~n)连一条容量为a[i]的边,(n+1~2*n)到t连一条容量为b[i]的边,再将…
题目链接: http://codeforces.com/problemset/problem/546/E E. Soldier and Traveling time limit per test1 secondmemory limit per test256 megabytes 问题描述 In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of…
B. Soldier and Traveling Time Limit: 1000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d      Java class name: (Any) Submit Status In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the …
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of ai soldiers. N…
In the country there are n cities and m bidirectional roads between them. Each city has an army. Army of the i-th city consists of ai soldiers. Now soldiers roam. After roaming each soldier has to either stay in his city or to go to the one of neighb…
题意 (CodeForces 546E) 对一个无向图,给出图的情况与各个节点的人数/目标人数.每个节点的人只可以待在自己的城市或走到与他相邻的节点. 问最后是否有解,输出一可行解(我以为是必须和答案一样,然后本机调了半天死活不一样,交上去结果A了- -). 分析 典型的网络流.问题在于建模.如何解决两个节点的人数->目标人数? 考虑到我们始终要和这两个状态打交道,不妨将每个结点拆成两个(转移前&转移后),这两个点间的流量是INF.如果两点相连(不妨设为u,u',v,v'),那么uu与v′v…
题目大概说一张无向图,各个结点初始有ai人,现在每个人可以选择停留在原地或者移动到相邻的结点,问能否使各个结点的人数变为bi人. 如此建容量网络: 图上各个结点拆成两点i.i' 源点向i点连容量ai的边 i'向汇点连容量bi的边 i向i'连容量INF的边 对于相邻的两点(u,v),u向v'连容量INF的边,v'向u连容量INF的边 跑最大流看看最大流是否等于∑bi.另外,注意∑ai不等于∑bi的情况. #include<cstdio> #include<cstring> #incl…
基础网络流,增加s和t,同时对于每个结点分裂为流入结点和流出结点.EK求最大流,判断最大流是否等于当前总人数. /* 304E */ #include <iostream> #include <string> #include <map> #include <queue> #include <set> #include <stack> #include <vector> #include <deque> #in…