缩点+染色+DFS codeforce467D】的更多相关文章

题目链接:https://vjudge.net/contest/219056#problem/A 推荐博客:https://blog.csdn.net/ck_boss/article/details/39429285 发现上面的这位大佬的思路和我一样,自己代码太多错误就参考了一下. 题意: 输入n,接下来会输入输入n个字符串,然后输入m,接下来会输入m对字符串,每一对表示左边的字符串可以变成右边的字符串,但是右边的不可以变成左边的.字符串不论大小写,现在要我们经过变换把一开始的n个字符里面的字符…
#1185 : 连通性·三 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 暑假到了!!小Hi和小Ho为了体验生活,来到了住在大草原的约翰家.今天一大早,约翰因为有事要出去,就拜托小Hi和小Ho忙帮放牧. 约翰家一共有N个草场,每个草场有容量为W[i]的牧草,N个草场之间有M条单向的路径. 小Hi和小Ho需要将牛羊群赶到草场上,当他们吃完一个草场牧草后,继续前往其他草场.当没有可以到达的草场或是能够到达的草场都已经被吃光了之后,小hi和小Ho就把牛羊群赶回家. 一开…
Problem Description A thief is running away! We can consider the city to N–. The tricky thief starts his escaping if and only if there is a street between cross u and cross v. Notice that he may not stay at the same cross in two consecutive moment. T…
Description You are to write a program that tries to find an optimal coloring for a given graph. Colors are applied to the nodes of the graph and the only available colors are black and white. The coloring of the graph is called optimal if a maximum…
题意:图上的点染色,给出的边的两个点不能都染成黑色,问最多可以染多少黑色. 很水的一题,用dfs回溯即可.先判断和当前点相连的点是否染成黑色,看这一点是否能染黑色,能染色就分染成黑色和白色两种情况递归,如果不能就单递归白色. 代码: #include <cstdio> #include <cstring> const int maxn = 110; int cas, v, e, M; bool g[maxn][maxn]; int color[maxn], rec[maxn]; v…
题目链接:https://vjudge.net/problem/POJ-2553 如果不会tarjan算法,推荐博客:https://blog.csdn.net/mengxiang000000/article/details/51672725 题意大意:第一行输入一个n(n==0时结束程序),和一个m分别代表点数和边数,接下来一行有2*m个数字,每两个数字u,v表示一条有向边,即u可以到达v. 假如一个点a可以到b,c,d,e这些点,并且这些点也可以到达a点,则a点就是符合要求的点,即一个点可以…
给一张无向图,要求你用黑白灰给点染色,且满足对于任意一个黑点,至少有一个白点和他相邻:对于任意一个白点,至少有一个黑点与他相邻,对于任意一个灰点,至少同时有一个黑点和白点和灰点与他相邻,问能否成功 Solution 显然灰色是多余的 首先考虑什么样的情况是不行的,显然仅在有孤立点的时候会挂,而连通图一定可以 所以我们只需要拿起每个连通块 DFS 随便染即可 #include <bits/stdc++.h> using namespace std; const int N = 1000005;…
Problem Description Kids in kindergarten enjoy playing a game called Hawk-and-Chicken. But there always exists a big problem: every kid in this game want to play the role of Hawk.  So the teacher came up with an idea: Vote. Every child have some nice…
Leo has a grid with N rows and M columns. All cells are painted with either black or white initially. Two cells A and B are called connected if they share an edge and they are in the same color, or there exists a cell C connected to both A and B. Leo…
http://codeforces.com/problemset/problem/272/E 把仇恨关系想象为边, 因为度只能为0,1,2,3,所以有以下几种 0,1 直接放即可 2: 有(1,1),(0,2)两种情况,第一种随便放,第二种放0那里 3:有(1,2),(0,3)两种情况,第一种放1,第二种放0那里 也就是说,怎样都有解 dfs寻找即可 不过一开始觉得这样不靠谱,因为时间复杂度很高,不过没想到过了 #include <cstdio> #include <vector>…