[题目]D. Almost Acyclic Graph [题意]给定n个点的有向图(无重边),问能否删除一条边使得全图无环.n<=500,m<=10^5. [算法]拓扑排序 [题解]找到一个简单环,则欲删除的边一定经过该环.尝试环上的每一条边(至多n条边)后再次拓扑排序判断全图是否有环. 拓扑排序后定位到简单环:剩余图是环+环内DAG,DFS过程中将走入死路的点标-1,访问过标1,找到访问过的点就是简单环.换起始点直到找到环为止. 复杂度O(nm). #include<cstdio>…
大意:给出一个有向图,问能否在只去掉一条边的情况下破掉所有的环 解析:最直接的是枚举每个边,将其禁用,然后在图中找环,如果可以就YES,都不行就NO 复杂度O(N*M)看起来不超时 但是实现了以后发现即使优化到不清空vis数组(时间戳标记),也仍然超时. 因为O(N*M)已经很接近时间复杂度上界,常数稍大就GG. 不过可以脑补一下取巧算法:在不超时的前提下,随机取K个边进行检验~~~.不过数据多了就非常容易GG.理论上还是可行的. 正解:从枚举边变为枚举点,删掉到达一个点的某条边可以认为是该点入…
https://www.lydsy.com/JudgeOnline/problem.php?id=2938 题意:给出N个01病毒序列,询问是否存在一个无限长的串不存在病毒序列 正常来说,想要寻找一个串是否出现这些01序列可以直接跑AC自动机,这题反向问有没有无限长的不出现,说明在AC自动机上询问的时候,要避免经过所有病毒串标记的end结点以及需要寻找一个可以无限跑的环. 所以我们将字典树的边和失配指针的边都看作是一条有向边,如果存在一个环上没有病毒结尾的标记,那么他就是合法的. 值得一提的是,…
http://acm.hdu.edu.cn/showproblem.php?pid=3342 Legal or Not Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5788    Accepted Submission(s): 2678 Problem Description ACM-DIY is a large QQ group w…
Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 39602   Accepted: 13944 Description An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from s…
One of my friends is always drunk. So, sometimes I get a bit confused whether he is drunk or not. So, one day I was talking to him, about his drinks! He began to describe his way of drinking. So, let me share his ideas a bit. I am expressing in my wo…
Almost Acyclic Graph CodeForces - 915D time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can…
C. Mail Stamps Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/29/C Description One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B…
E. Minimal Labels time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any p…
传送门 •题意 给你两个数组 p,q ,分别存放 1~n 的某个全排列: 让你根据这两个数组构造一个字符串 S,要求: (1)$\forall i \in [1,n-1],S_{pi}\leq S _{pi+1}  ,\forall i \in [1,n-1],S_{qi} \leq S _{qi+1}$ (2)字符串 S 至少包含 k 个不同的小写字母: •思路 类似于牛客第五场的H 不过由于这个不知道字母是什么,需要利用强联通分解, 把属于同一个强联通块的位置置于同一个字母, 然后根据前后关…