codeforces 915 D Almost Acyclic Graph

六个月入门机器人工程师:从ROS到建图导航的系统集成实战路线 机器人开发正在从单一学科走向多技术融合的系统工程,涵盖嵌入式控制、感知算法与上层应用。理解机器人系统的核心在于掌握ROS通信机制、坐标变换与传感器数据处理等基本原理,这些构成了智能机器人建图导航与自主抓取的技术基石。随着服务机器人与智能制造场景加速落地,行业对具备系统集成能力的机器人工程师需求持续上升,从激光雷达建图、自主定位导航到机械臂视觉抓取,均需要开发者打通硬件驱动、算法部署与调试优化的完整链路。针对零基础或转行人群,聚焦ROS、Linux、Python及Cartographer等工具链,结合差速底盘 阅读详情

Description

You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it.

Can you make this graph acyclic by removing at most one edge from it? A directed graph is called acyclic iff it doesn’t contain any cycle (a non-empty path that starts and ends in the same vertex).

Input

The first line contains two integers n and m (2 ≤ n ≤ 500, 1 ≤ m ≤ min(n(n - 1), 100000)) — the number of vertices and the number of edges, respectively.

Then m lines follow. Each line contains two integers u and v denoting a directed edge going from vertex u to vertex v (1 ≤ u, v ≤ n, u ≠ v). Each ordered pair (u, v) is listed at most once (there is at most one directed edge from u to v).

Output

If it is possible to make this graph acyclic by removing at most one edge, print YES. Otherwise, print NO.

Examples

Input
3 4
1 2
2 3
3 2
3 1
Output
YES

Input
5 6
1 2
2 3
3 2
3 1
2 1
4 5
Output
NO

Note

In the first example you can remove edge , and the graph becomes acyclic.

In the second example you have to remove at least two edges (for example, and ) in order to make the graph acyclic.


题意:给一个有向边的图,判断能否去掉一条边使其成为无环图。
思路:先dfs搜索一遍,把找到的第一个环返回;如果没有环打印YES。要成为无环图,那么这个环上一定要去掉一条边。所以只需要遍历这个环上所有的边,检查去掉后图上还有无其他的环,如果去掉一条边后图上无环,那么打印YES;如果去掉任何一条边都不能,打印NO。

#include<stdio.h>
//#include<iostream>
//using std::cin;
//using std::cout;
//#include<algorithm>
//using std::sort;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mabs(x) ((x)>0?(x):(0-(x)))
#define N_max 505
#include<memory.h>
int n,m;
int g[N_max][N_max] = { 0 };

int vis[N_max] = { 0 };
int ring[N_max] = { 0 };
int nring = 0;

int chk[N_max] = { 0 };
int checkring(int cur) {//dfs只检查有无环
    if (chk[cur] == -1)
        return 0;

    chk[cur] = -1;
    for (int next = 1; next <= n; ++next) {
        if (chk[next] != 1 && g[cur][next] == 1) {
            if (0== checkring(next)) {
                return 0;
            }
        }
    }
    chk[cur] = 1;
    return 1;
}

int findring(int cur,int rdx) {//dfs,检查有无环,并返回遇到的第一个环
    if (vis[cur] == -1) { 
        ring[rdx] = cur; nring = rdx;
        return 1; 
    }
    vis[cur] = -1; 
    for (int next = 1; next <= n; ++next) {
        if (vis[next]!=1&&g[cur][next]==1) {
            if (1 == findring(next,rdx+1)) { 
                ring[rdx] = cur;
                return 1; 
            }
        }
    }
    vis[cur] = 1;
    return -1;
}
int main() {
    scanf("%d %d", &n,&m);
    int a1, a2;
    for (int i = 0; i < m; ++i) {
        scanf("%d %d", &a1, &a2);
        g[a1][a2] = 1;
    }

    for (int i = 1; i <= n; ++i)
    {
        nring = 0;
        if (1 == findring(i,0)) {
            break;
        }
    }
    int pflag = 0,rflag;
    if (nring == 0) {
        printf("YES"); return 0;
    }
    ++nring;
    for (int i = 0; i<nring&&pflag==0; ++i) {
        memset(chk, 0, sizeof chk);
        g[ring[i]][ring[(i + 1) % nring]] = 0;
        rflag = 1;
        for (int t = 1; t <= n&&rflag;++t)
            rflag = checkring(t);//有环返回0
        pflag = rflag;
        g[ring[i]][ring[(i + 1) % nring]] = 1;

    }
    if (pflag)printf("YES");
    else printf("NO");
}
KEGG数据库与KAAS工具:基因功能注释的实用指南 本文提供了使用KEGG数据库与KAAS工具进行基因功能注释的完整实用指南。详细阐述了如何从准备基因或蛋白序列开始,通过KAAS服务器获取KEGG Orthology(KO)编号,并解读注释结果。文章进一步介绍了如何利用KOBAS工具进行通路富集分析,将定性观察转化为定量洞察,并分享了提高注释准确率、处理大数据集及使用API等避坑技巧与高阶方法,为基因组学、转录组学研究者奠定坚实的数据分析基础。 阅读详情

相关推荐

OpenWRT端口转发与NAT环回冲突的排查与解决

本文详细解析了OpenWRT路由器中端口转发与NAT环回功能冲突导致的内网访问故障。通过生活化类比阐明两者工作原理,提供从基础诊断到内核参数调整、LuCI选项配置及手动编写iptables规则的多套解决方案,并给出进阶排查思路,帮助用户彻底解决内网无法通过公网地址访问服务的常见问题。

weixin_29243279的博客 505

codeforces-915D Almost Acyclic Graph(拓扑序判圈)

链接:http://codeforces.com/problemset/problem/915/D题意:在一个有向图中,判断能不能至多删除一条边使得该图不含圈,n&lt;=500, m&lt;=100000题解:枚举每一个点,让该点的入度减一,然后拓扑序判圈代码:#include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;cstring&...

GrimCake的博客 339

基于DFT的scanshift sdc模板(DFT)

摘要:本文详细介绍了DFT测试模式下的SDC约束方法。

murphyrong的博客 882

【CodeForces】915 D. Almost Acyclic Graph 拓扑排序找环

【题目】D. Almost Acyclic Graph 【题意】给定n个点的有向图(无重边),问能否删除一条边使得全图无环。n<=500,m<=10^5。 【算法】拓扑排序 【题解】找到一个简单环,则欲删除的边一定经过该环。尝试环上的每一条边(至多n条边)后再次拓扑排序判断全图是否有环。 拓扑排序后定位到简单环:剩余图是环+环内DAG,DFS过程中将走入死路的点标-1,访问过标...

weixin_34062469的博客 224

如何解决ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE.

解决ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE

2742

eNSP安装教程

eNSP安装教程一、安装eNSP1、先安装依赖组件2、安装eNSP主程序eNSP+V100R003C00SPC100+Setup ---不要安装在中文路径下3、安装完成后注册设备 一、安装eNSP 程序包位置:https://drive.weixin.qq.com/s?k=AOgAQQfOAAsw1wAKEgAAcAbgbSAKQ 1、先安装依赖组件 依赖组件: WinPcap_4_1_3 —直接下一步,但不要安装在中文路径下 Wireshark_v3.4.6 或者wireshark-win3

qimowei的博客 8667

codeforces 915D Almost Acyclic Graph 拓扑判环(Onm)

题意:给定有向图,问删掉一条边能否使得整个图无环思路:点不多,但是边很多,枚举删掉哪条边再判环不可行,所以有两种优化方法:法一:先判是否有环,如果有的话找到一个环,因为要删的哪条边一定来自这个环,这样的话只要枚举这个环上的边就够了(On),然后判删掉后有没有环,复杂度可以做到Onm;法二:我们用拓扑判环的方法(On),只需要知道每个点的入度就可以了,对于这个题,只要证明可行性无需找到删掉哪个边,然...

床前明月光 325

S32K144之芯片锁死解锁——关闭debug端口

S32K144之芯片锁死及解锁 经常捣鼓单片机就会发现,时常会因为某些操作不当导致芯片锁死情况的发生,通过Jlink我们可以读到芯片的ID,但是无法进行Debug,这很是让人苦恼。 基于S32K144的芯片锁死,一般有如下几种可能: 1、时钟配置异常,过高的配置时钟频率以及不配置时钟,都有可能造成芯片保护锁死,我就曾经因为不注意把时钟配置代码注释掉,导致芯片锁死。 2、我是微软雅黑烧写断电,如果在...

weixin_41935674的博客 1万+

codeforces915D. Almost Acyclic Graph(拓扑)

D. Almost Acyclic Graph time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given adir...

Amove 367

安防相机宽动态(WDR)技术解析:从原理到实战应用

本文深入解析安防相机宽动态(WDR)技术原理,对比多次曝光与DOL-WDR等实现方式,并区分硬件WDR与数字WDR(DWDR)的本质差异。文章重点阐述了WDR在逆光出入口、夜间道路监控等五大典型场景的实战应用与调参技巧,旨在帮助用户根据实际需求正确选择与配置,确保监控系统在复杂光线下清晰成像。

weixin_29191081的博客 427

手把手用LTspice仿真运算放大器电路:从虚短虚断到频响分析

本文通过LTspice仿真软件,手把手教你从搭建基础运算放大器电路开始,验证虚短虚断原理,并逐步深入频响分析与稳定性探究。内容涵盖反相/同相放大器、积分器仿真,导入真实运放模型进行蒙特卡洛分析,以及利用交流分析和波特图评估电路性能,帮助工程师和学生将抽象理论转化为直观、可测量的仿真结果,提升电路设计实战能力。

salt9的博客 1094

codeforces 915 D. Almost Acyclic Graph(拓扑排序)

题目链接:http://codeforces.com/problemset/problem/915/D思路:枚举删除的边肯定会T掉,因为只能删除一条边,所以可以枚举节点,删除一条边就有一个节点的入度-1,然后拓扑排序,看是不是能够成立。#include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include...

llmxby 303

AXI总线详解完结篇

经过几个月的整理和发文,AXI总线详解系列正式迎来最终篇,内容基本涵盖了上一篇文章的全部内容。 所有文章的链接如下: 1、 AXI总线详解 2、AXI总线详解-总线和接口以及协议 3、AXI协议中的通道结构 4、AXI总线详解-AXI4读写操作时序及AXI4猝发地址及选择 5、AXI4交换机制 6、ZYNQ中DMA与AXI4总线-DMA简介 7、AXI总线详解-不同类型的DMA 8、AXI总线详解-DMA内部寄存器的读写方式 9、AXI总线详解-几种应用DMA的场合 10、Altera Scatter-G.

OpenFPGA的博客 5486

codeforces 915D Almost Acyclic Graph 【拓扑】

D. Almost Acyclic Graph 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 an...

甜晨流年 381

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

CodeForces 915D Almost Acyclic Graph

Description You are given a directed graph consisting of \(n\) vertices and \(m\) edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edg...

weixin_34270865的博客 127

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Codeforces 915D - Almost Acyclic Graph(拓扑排序)

D. Almost Acyclic Graph 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 an...

辞树 286

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Codeforces 915D Almost Acyclic Graph

题意翻译 给定一个n个顶点,m条边的有向图。你允许从其中去掉最多一条边。 你能够去掉最多一条边就让这个图无环吗?我们称一个有向图无环,当且仅当它不包含一个环(起点和终点相同的路径)。 输入格式: 第一行两个正整数n,mn,m2\le n\le 500,1\le m\le min(n(n-1),100000)2≤n≤500,1≤m≤min(n(n−1),100000),代表图的顶点数和边...

weixin_30677617的博客 89

Codeforces Contest 915 problem D Almost Acyclic Graph —— 枚举+拓扑

You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. Can you m...

天翼之城的博客 187

Almost Acyclic Graph CodeForces - 915D

Almost Acyclic Graph CodeForces - 915D You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to ...

Focus5679的博客 247

Almost Acyclic Graph(【CodeForces】915 D)

【题意】n个点m条边,判断是否可以通过删除一条边使整个图不存在环。 【题解】看到题目的第一反应是Tarjan求强连通,求完强连通后,假如存在两个及以上的强连通分量中存在两个点以上,肯定是不行的。因为一个强连通分量中如果点数大于1肯定存在环,存在多个环一定是不能通过删除一条边解决的。然后对于只有一个强连通分量里面有一大堆的情况分析,可能这一个分量中存在的环不能通过删除一条边解决也可能可以,我当时的

sdut16szq的博客 470

CodeForces 915D :Almost Acyclic Graph 拓扑排序

传送门 题目描述 给定一个 nnn个顶点, mmm条边的有向图。你允许从其中去掉最多一条边。 你能够去掉最多一条边就让这个图无环吗?我们称一个有向图无环,当且仅当它不包含一个环(起点和终点相同的路径)。 分析 比较裸的思路就是每次删去一条边,然后拓扑排序,但是这样复杂度就O(n∗m∗m)O(n * m * m)O(n∗m∗m),显然会爆掉 那有没有优化的方法呢?我们去分析一下拓扑排序的过程,为什么有环就会导致无法进行拓扑排序,因为入度没有办法减为0,没办法进入队列从而计数,所以我们可以尝试去枚举点,去减少他

tlyzxc的博客 183

codeforces 915D Almost Acyclic Graph 拓扑排序

大意:给出一个有向图,问能否在只去掉一条边的情况下破掉所有的环 解析:最直接的是枚举每个边,将其禁用,然后在图中找环,如果可以就YES,都不行就NO 复杂度O(N*M)看起来不超时 但是实现了以后发现即使优化到不清空vis数组(时间戳标记),也仍然超时。 因为O(N*M)已经很接近时间复杂度上界,常数稍大就GG。 不过可以脑...

weixin_30739595的博客 109

CodeForces - 915D Almost Acyclic Graph 拓扑排序

题目:D. Almost Acyclic Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a directed graph consisting of n vertices and m edges (each...

Reast1nPeace的博客 427

【拓扑排序专题】CodeForces - 915D Almost Acyclic Graph

https://vjudge.net/problem/CodeForces-915D D. Almost Acyclic Graph Description You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can be traversed in ...

荷叶田田 474

CodeForces 915D Almost Acyclic Graph(拓扑排序)

这题居然是topsort…… 大致题意就是给你一个图,然后最短删除一条边,问你是否能够把这个图变成一个DAG有向无环图。 暴力的话枚举所有的边,然后再遍历图,复杂度为O(M*(N+M))果断超时。自己画出图来找一些环的个数以及相互之间的重边的关系,还是没有能够找到一个很好的规律。另一个方法就是,找出一个的环,然后标记环上的边,枚举这些边删掉,看是否还有环。但是这个操作起来不好处理,本身求具体的环就要用tarjan,然后还要在上面修改标记下环上的边…… 正解是,

alpc_qleonardo 677
上一篇: 2018 CCCC L1 001 天梯赛座位分配
下一篇: codeforces 911 E. Stack Sorting
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值