CF-1144F-Graph Without Long Directed Paths】的更多相关文章

<题目链接> 题目大意:给定一个无向图,该无向图不含自环,且无重边.现在要你将这个无向图定向,使得不存在任何一条路径长度大于等于2.然后根输入边的顺序,输出构造的有向图.如果构造的边与输入的方向一致,就输出1,方向不一致就输出0. 解题分析:因为定向后的图不能存在长度大于等于2的路径,所以我们直接对原图进行奇偶染色.如果碰到了奇环,就直接输出"NO",否则就对该图奇偶染色,进行地定向.$col[u]$表示以$u$为起点的边所染的颜色. #include <bits/s…
题意: 输入一张有向图,无自回路和重边,判断能否将它变为有向图,使得图中任意一条路径长度都小于2. 如果可以,按照输入的边的顺序输出构造的每条边的方向,构造的边与输入的方向一致就输出1,否则输出0. 题解: 当我看到"图中任意一条路径长度都小于2"这句话的时候我都懵了,不知道这道题让干啥的. 最后没想到就是句面意思,因为题目中给你了m条无向边,每条无向边长度都是1,那么所有路径长度都小于2,就要这样做: 比如无向图边为: 1 2 2 3 3 4 那么变成有向图就要 1->2 2&…
        F. Graph Without Long Directed Paths time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a connected undirected graph consisting of nn vertices and mm edges. There are no…
F. Graph Without Long Directed Paths time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a connected undirected graph consisting of nn vertices and mm edges. There are no self-lo…
You are given a connected undirected graph consisting of nn vertices and mm edges. There are no self-loops or multiple edges in the given graph. You have to direct its edges in such a way that the obtained directed graph does not contain any paths of…
题意:有\(n\)个点和\(m\)条无向边,现在让你给你这\(m\)条边赋方向,但是要满足任意一条边的路径都不能大于\(1\),问是否有满足条件的构造方向,如果有,输出一个二进制串,表示所给的边的方向. 题解:我们先单独拿出\(3\)个点来看,选择一个点,那么与它相连的另外两个点到自己的方向一定是相同的,同理,我们可以推广到任意一个点,与它相连的所有点到它的方向必须都是一样的才行,其实到这儿就不难看出可以用二分图染色来写了,然后打个板子就能很愉快的AC啦~ 代码: int n,m; int a,…
C. Graph Reconstruction time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output I have an undirected graph consisting of n nodes, numbered 1 through n. Each node has at most two incident edges. Fo…
Graph And Its Complement time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Given three numbers n,a,bn,a,b. You need to find an adjacency matrix of such an undirected graph that the number of…
LINK:Divisor Paths 考试的时候已经想到结论了 可是质因数分解想法错了 导致自闭. 一张图 一共有D个节点 每个节点x会向y连边 当且仅当y|x,x/y是一个质数. 设f(d)表示d的约数个数 那么x->y的无向边的边权为f(x)-f(y); 每次询问两个点x,y之间的最短路径的条数有多少条,保证x|D,y|D. 不妨假设x>y.当y|x时容易发现y只需要每次在保证次数大于x的质因子上不断将自己本身的一个质数因子去掉即可. 不难发现 此时最短路长度为1 因为不管中间去的方式如何…
题意: 给出一个无向联通图,要求你给出每条边的方向,使得无论从哪个点出发最多只能走一条边: 思路: 对于每个点,要么出度为0,要么入度为0即可.所以这就是一个判断二分图. 二分图 #include "cstdio" #include "cstring" #include "iostream" #include "vector" using namespace std; typedef pair<int, int>…