题目大意

给你一个\(n\)个点的环,每条边有方向,改变第\(i\)条边的方向代价为\(w_i\),问将其改为强连通图的最小代价。\(n\leqslant100\)

题解

求出把边全部改为顺时针和全部改为逆时针的代价,较少的输出即可

卡点

C++ Code:


#include <cstdio>
#include <iostream>
#include <algorithm>
const int maxn = 111; int head[maxn], cnt;
struct Edge { int to, nxt; } e[maxn << 1];
void addedge(int a, int b) {
e[++cnt] = (Edge) { b, head[a] }; head[a] = cnt;
e[++cnt] = (Edge) { a, head[b] }; head[b] = cnt;
} int n, dep[maxn], l[maxn], r[maxn], w[maxn], res1, res2;
void dfs(int u) {
for (int i = head[u], v; i; i = e[i].nxt) {
v = e[i].to;
if (!dep[v]) dep[v] = dep[u] + 1, dfs(v);
}
} int main() {
std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
std::cin >> n;
for (int i = 1; i <= n; ++i) {
std::cin >> l[i] >> r[i] >> w[i];
addedge(l[i], r[i]);
}
dfs(dep[1] = 1);
for (int i = 1; i <= n; ++i) {
if (dep[r[i]] != dep[l[i]] % n + 1) res2 += w[i];
else res1 += w[i];
}
std::cout << std::min(res1, res2) << '\n';
return 0;
}

[CF24A]Ring road(2019-11-15考试)的更多相关文章

  1. 2019.11.15 JQ图片轮播

    <div class="three"> <div class="bjtp"> <img class="bjpic b1& ...

  2. CodeForces 24A Ring road(dfs)

    A. Ring road time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  3. Sprint1(第二天11.15)

    Sprint1(第二天11.15) Sprint1第一阶段 1.类名:软件工程-第一阶段 2.时间:11.14-11.23 3.选题内容:web版-餐厅到店点餐系统 4.团队博客地址: http:// ...

  4. Notes of Daily Scrum Meeting(11.15)

    Notes of Daily Scrum Meeting(11.15) 今天周六我们的主要工作是把这周落下的一些工作补回来,这是写程序的最后阶段,准备进入测试阶段了,所以之前的工作 要补齐,今天大家的 ...

  5. 11.15 Daily Scrum

    今天是假期回来的第一个周末,也是我们团队的又一次进度汇总总结和调试工作开展,鉴于一周以来大家的工作有了很大的成果,所以,本次召开的会议主旨在于解决一些开发方面的细节问题,达成共识,为日后进一步的功能方 ...

  6. 2017.11.15 String、StringBuffer、StringBuilder的比较(todo)

    参考来自:http://blog.csdn.net/jeffleo/article/details/52194433 1.速度 一般来说,三者的速度是:StringBuilder > Strin ...

  7. 2017-3-13 leetcode 4 11 15

    ji那天居然早起了,惊呆我了,眼睛有点儿疼,一直流泪....继续保持 ========================================================== leetco ...

  8. 比较两个时间的大小 举例:CompareDate("12:00","11:15")

    //比较两个时间的大小 举例:CompareDate("12:00","11:15") function CompareDate(t1, t2) { var d ...

  9. Python3.7&Django1.11.15 兼容性问题

    环境: 1. Windows10 2. python3.7 3. Django1.11.15 启动Django时抛出以下异常: Unhandled exception in thread starte ...

随机推荐

  1. 02篇ELK日志系统——升级版集群之kibana和logstash的搭建整合

    [ 前言:01篇LK日志系统已经把es集群搭建好了,接下来02篇搭建kibana和logstash,并整合完成整个ELK日志系统的初步搭建. ] 1.安装kibana 3台服务器: 192.168.2 ...

  2. maven仓库报错 sqljdbc4、ojdbc6、tomcat-jdbc-8.5.14

    报错:Cannot resolve com.microsoft.sqlserver:sqljdbc4:4.0  和  Missing artifact com.microsoft.sqlserver: ...

  3. Nginx 高级配置-自定义json格式日志

    Nginx 高级配置-自定义json格式日志 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在大数据运维工作中,我们经常会使用flume,filebeat相关日志收集工具取收集日志 ...

  4. 十八、Python面向对象之魔术方法

    1.类的比较 class A(object): def __init__(self,value): self.value = value def __eq__(self,other): return ...

  5. 解决nginx反向代理webservice的soap:address location问题

    原文:https://blog.csdn.net/mn960mn/article/details/50716768 一:首先来发布一个web service package com.ws.servic ...

  6. IE float 双边距

    IE 浮动元素的双边距

  7. GIL全局解释器锁及协程

    GIL全局解释器锁 1.什么是GIL全局解释器锁 GIL本质是一把互斥锁,相当于执行权限,每个进程内都会存在一把GIL同一进程内的多线程,必须抢到GIL之后才能使用Cpython解释器来执行自己的代码 ...

  8. Kubernetes安全策略

    Kubernetes CIS Benchmark 见kube-bench 1.安全策略 1.1 使用宿主节点的命名空间 命名空间分 网络命名空间 PID命名空间 IPC命名空间 Pod使用主机的网络命 ...

  9. [KCOJ3393]上马

    题目描述 Description Chicken在IEC(International Equestrianism Competition(国际马术表演赛))惨跪,没有成功的上到马,他深刻的记得他的选手 ...

  10. Python面向对象 | 类方法 classmethod

      类方法:必须通过类的调用,而且此方法的意义:就是对类里面的变量或者方法进行修改添加. 例一个商店,店庆全场八折,代码怎么写呢? class Goods: __discount = 0.8 # 折扣 ...