题目大意

给你一个\(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. 下载win10系统

    有时候想重装系统但总找不到下载的地方,今天记录一下.nsdn我告诉你,这里有许多软件下载 网站URL:https://msdn.itellyou.cn/ 我想下载一个Windows10 磁力地址 ed ...

  2. Linux的rpm管理

                            书山有路勤为径,学海无涯苦作舟 自学linux已经有几天了,感觉还可以.坚持下去,就会有收获. 每个系统都用相应的软件的管理,Linux也不例外.下面讲 ...

  3. centos 查看硬盘情况

    lsblk                                                                             查看分区和磁盘 df -h     ...

  4. Anaconda 安装 tensorflow 和 keras

    说明:此操作是在 Anaconda Prompt 窗口完成的 CPU版 tensorflow 的安装. 1.用 conda 创建虚拟环境 tensorflow python=3.6 conda cre ...

  5. 搜狐视频 登录 md5 加密破解

    这是一个简单的md5加密,可以学习一下js加密的破解流程,当一个入门级的教程 第一步:请求抓包 password是32位的字母和数字组合,猜测可能是md5加密,我们md5在线工具上试一下 发现我们的猜 ...

  6. No qualifying bean of type 'com.chinanums.agent.operation.service.component.OperationPageComponent' available:

    java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...

  7. NOIP 2013 积木大赛

    洛谷 P1969 积木大赛 洛谷传送门 JDOJ 2229: [NOIP2013]积木大赛 D2 T1 JDOJ传送门 题目描述 春春幼儿园举办了一年一度的"积木大赛".今年比赛的 ...

  8. django ORM CRUD

    一.增加数据-Create 1.类名.objects.create(属性=值,属性=值) Myomodel.objects.create(name=) 2.d={"属性":&quo ...

  9. FFT和NTT学习笔记_基础

    FFT和NTT学习笔记 算法导论 参考(贺) http://picks.logdown.com/posts/177631-fast-fourier-transform https://blog.csd ...

  10. Problem B. 即时战略 ———2019.10.12

    题目:   代码~:感谢土蛋 #include <iostream> #include <cstring> #include <cmath> #include &l ...