One-Way Reform】的更多相关文章

Description There are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and there is no road which connects the city with itself. It is possible tha…
E. New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connecte…
题目链接: 题目 E. New Reform time limit per test 1 second memory limit per test 256 megabytes inputstandard input outputstandard output 问题描述 Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities…
Description Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only th…
One-Way Reform time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one…
E. One-Way Reform 题目连接: http://codeforces.com/contest/723/problem/E Description There are n cities and m two-way roads in Berland, each road connects two cities. It is known that there is no more than one road connecting each pair of cities, and ther…
BEIJING—China's family-planning agency is projecting a slow rollout for an easing of its one-child policy, underscoring reluctance by the government in moving too quickly to let some couples have two children and a law in place for decades. rollout:首…
E. New Reform 题目连接: http://www.codeforces.com/contest/659/problem/E Description Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guara…
题意:给你一个无向图,如今要求你把边改成有向的. 使得入度为0的点最少,输出有多少个点入度为0 思路:脑补一波结论.假设有环的话显然没有点入度为0,其余则至少有一个点入度为0,然后就DFS一波就能够了 #include <cstdio> #include <queue> #include <cstring> #include <iostream> #include <cstdlib> #include <algorithm> #inc…
BEIJING -- China's State Council, the cabinet, on Monday unveiled this year's priorities for economic reforms. The reforms -- to streamline administration and deregulate power to lower levels, promote the yuan's convertibility under the capital accou…
题目链接: E. New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is co…
E. New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connecte…
Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing r…
Description Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It isnot guaranteed that you can get from any city to any other one, using only the…
// CF 732F Tourist Reform // 思路:两遍tarjan // 找强联通分量 #include <bits/stdc++.h> using namespace std; #define LL long long typedef pair<int,int> pii; const int inf = 0x3f3f3f3f; ; #define clc(a,b) memset(a,b,sizeof(a)) ; ; void fre() {freopen("…
New Reform time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected b…
题意:给你n点m边的图,然后让你确定每条边的方向,使得入度=出度的点最多 . 度数为偶数的点均能满足入度 = 出度. 证明:度数为奇数的点有偶数个,奇度点两两配对连无向边,则新图存在欧拉回路,则可使新图所有点入度 = 出度. #include <bits/stdc++.h> using namespace std; #define X first #define Y second typedef long long ll; ; int d[N], head[N], tot; int to[N*…
题目链接 对于每一个联通块, 如果有一个强连通分量, 那么这个联通块对答案的贡献就是0. 否则对答案贡献是1. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <complex> #include <cmath> #include <map> #inc…
题目链接:传送门 题目大意:一副无向图,要求你给边定向(变为有向图),使出度等于入度的点最多,输出有多少 个点,并且输出定向后的边(前为起点,后为终点) 题目思路:欧拉路 我们这样考虑,先考虑无向图的点的度数,如果为奇数则一定无法变为题目要求的点,ans-1 对于度为偶数的点则一定可以通过调整满足. 处理方法:新建一个虚拟节点0,使所有度为奇数的点向其连一条边,那么最终图中的点的度数都为偶数. 这样就满足欧拉路的条件了.我们只需要跑欧拉路并且将走过的路径保留下来即可. 注意将与虚拟节点连的边删去…
边双连通分量. 这题有一点构造的味道.一个有向图,经过强连通缩点之后会形成一个有向无环图. 如果将最大的强连通分量放在顶端,其余的强连通分量都直接或间接指向他,那么这样就构造出了符合要求的图. 接下来就是要去寻找强连通分量.对于一个无向图来说,每一个边-双联通分量都可以将每条边定向之后构造成一个强连通分量,$dfs$一遍即可. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #…
构造. 有一种十分巧妙的方法可以使图中所有度数为偶数的节点,经过每条边定向后,出度和入度都相等. 首先统计每个节点的度数,将度数为奇数的节点与编号为$n+1$的节点连边,这样一来,这张新图变成了每个节点的度数都是偶数的图,必然存在欧拉回路.任意一条欧拉回路都使得原图中度数为偶数的节点的出度与入度相等. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cs…
题目:http://codeforces.com/contest/732/problem/F 给无向图定向使得从每个点出发能去的点数最小值最大. SCC.点内部dfs定向.点间以siz最大的为起点反向dfs. 自我感觉良好的自己写法:在新连边的时候只是操作一下 thd 和 tnxt 即可. 注意写了构造函数的话结构体成员的初值就不是自动赋值为0了. #include<iostream> #include<cstdio> #include<cstring> using n…
前言:关于如何求双连通分量,我们可以在tarjan搜索时标记下所有桥的位置(双连通分量(可以认为是没有桥的无向图图)即可通过删去所有桥得到),那么怎么找桥呢,对于每一条搜索到的边u->x,如果low[u]>dfn[x]则说明u不能通过子图到达比x更早的节点,那么就说明该边是桥 题意:把一个无向图变成有向图,对于这个有向图来说,每个点的价值是它所有能到达的点的数量,要求使得所有点中最小的价值最大 题解:现学的边-双联通分量,先求一遍边-双联通分量,然后在每个双连通分量里dfs一边把双向边变成单向…
题目链接:http://codeforces.com/problemset/problem/732/F 题意: 给出一个有n个点m条边的无向图,保证联通,现在要求将所有边给定一个方向使其变成有向图,设f(x)为点x能到达的点的个数,要求使最小的f(x)最大,并输出方案. 思路: tarjan一下,答案肯定是强连通分量里点最多的一个分量,而同一个强连通里的点成环,其他分量都指向这个最大点个数的分量. 退役了,偶尔刷一下题... #include <bits/stdc++.h> using nam…
分析转载自http://blog.csdn.net/yukizzz/article/details/51029628 题意: 给定n个点和m条双向边,将双向边改为单向边,问无法到达的顶点最少有多少个? 分析: 无法到达的话即入度为0. DFS判断每一个连通块中是否存在环,如果存在环,就能保证环中每个点的入度都大于等于1.否则,有头有尾,头的入度为0. ..]of longint; n,m,x,y,tmp,ans,tot,i:longint; procedure add(a,b:longint);…
求出无向图的所有边双联通分量,然后缩点就成了一颗树. 然后我们选取最大的那个边双联通分量作为根,这样我们就可以确定所有割边的方向了. 对于边双联通分量里面的边,我们随便dfs一下就可以把它变成强连通分量,方向也就确定了. #include <bits/stdc++.h> using namespace std; vector<]; vector<pair<]; set<pair<int, int>> bridge; set<pair<int…
题目链接: http://codeforces.com/problemset/problem/659/E 题意: 给定n个点和m条双向边,将双向边改为单向边,问无法到达的顶点最少有多少个? 分析: 无法到达的话即入度为0. DFS判断每一个连通块中是否存在环,如果存在环,就能保证环中每个点的入度都大于等于1.否则,有头有尾,头的入度为0. 代码: #include<cstdio> #include<queue> #include<cstring> #include<…
题目:http://codeforces.com/contest/732/problem/F 首先把边双缩点,边双内部 dfs 一个顺序一定是可以从每个点走到边双内部所有点的,因为它是以环为基本单位: 然后对于缩点之后的图,找到 siz 最大的点作为根 dfs,再连反边,那么只有 siz 最大的那个点只能走到自己内部,就可以使答案最大: 结构体要开得精细一点,防止爆空间?还是什么奇奇怪怪的错误之类的... 代码如下: #include<iostream> #include<cstdio&…
[题目链接]:http://codeforces.com/contest/732/problem/F [题意] 给你一张无向图; n个点,m条边; 让你把这张图改成有向边 然后定义r[i]为每个点能够到达的其他点的数目; 让你使得最小的r[i]尽可能地大; 让你输出这个尽可能大的最小的ri; 然后输出改边之后的有向图; [题解] 如果整张图是一个环的话; 这个环上的每个点的答案就是确定的; 即为这个环的大小; 则考虑把原图缩点; 缩点之后; 每个环都能成为一个点; 则最后的答案就是强连通分量中所…
[题目链接]:http://codeforces.com/contest/723/problem/E [题意] 给你一个无向图; 让你把这m条边改成有向图; 然后使得出度数目等于入度数目的点的数目最多; 输出这个点的数目; 同时输出更改之后的所有有向边 [题解] 需要先明确; 就是图中度数为奇数的点的个数肯定是偶数个; 因为每条边都会贡献2度数; 所以最后的总度数肯定是偶数的; 则奇度数的点肯定得是偶数个,不然最后不会满足总度数为偶数; 知道这个之后; 猜想; 最后的答案就为原图中度数为偶数的点…