热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

usaco4.2.1DrainageDitches

一原题DrainageDitchesHalBurchEverytimeitrainsonFarmerJohnsfields,apondformsoverBessiesfavorit

一 原题


Drainage Ditches
Hal Burch

Every time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. This means that the clover is covered by water for awhile and takes quite a long time to regrow. Thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. Instead, the water is drained to a nearby stream. Being an ace engineer, Farmer John has also installed regulators at the beginning of each ditch, so he can control at what rate water flows into that ditch.

Farmer John knows not only how many gallons of water each ditch can transport per minute but also the exact layout of the ditches, which feed out of the pond and into each other and stream in a potentially complex network. Note however, that there can be more than one ditch between two intersections.

Given all this information, determine the maximum rate at which water can be transported out of the pond and into the stream. For any given ditch, water flows in only one direction, but there might be a way that water can flow in a circle.

PROGRAM NAME: ditch

INPUT FORMAT

Line 1:Two space-separated integers, N (0 <&#61; N <&#61; 200) and M (2 <&#61; M <&#61; 200). N is the number of ditches that Farmer John has dug. M is the number of intersections points for those ditches. Intersection 1 is the pond. Intersection point M is the stream.
Line 2..N&#43;1:Each of N lines contains three integers, Si, Ei, and Ci. Si and Ei (1 <&#61; Si, Ei <&#61; M) designate the intersections between which this ditch flows. Water will flow through this ditch from Si to Ei. Ci (0 <&#61; Ci <&#61; 10,000,000) is the maximum rate at which water will flow through the ditch.

SAMPLE INPUT (file ditch.in)

5 4
1 2 40
1 4 20
2 4 20
2 3 30
3 4 10

OUTPUT FORMAT

One line with a single integer, the maximum rate at which water may emptied from the pond.

SAMPLE OUTPUT (file ditch.out)

50






二 分析


裸最大流。因为那行应该注释掉的代码TLE了两次。。


三 代码


运行结果&#xff1a;

USER: Qi Shen [maxkibb3]
TASK: ditch
LANG: C&#43;&#43;Compiling...
Compile: OKExecuting...Test 1: TEST OK [0.000 secs, 4348 KB]Test 2: TEST OK [0.000 secs, 4348 KB]Test 3: TEST OK [0.000 secs, 4348 KB]Test 4: TEST OK [0.000 secs, 4348 KB]Test 5: TEST OK [0.000 secs, 4348 KB]Test 6: TEST OK [0.000 secs, 4348 KB]Test 7: TEST OK [0.000 secs, 4348 KB]Test 8: TEST OK [0.000 secs, 4348 KB]Test 9: TEST OK [0.000 secs, 4348 KB]Test 10: TEST OK [0.011 secs, 4348 KB]Test 11: TEST OK [0.000 secs, 4348 KB]Test 12: TEST OK [0.000 secs, 4348 KB]All tests OK.

Your program (&#39;ditch&#39;) produced all correct answers! This is your submission #3 for this problem. Congratulations!




AC代码&#xff1a;

/*
ID:maxkibb3
LANG:C&#43;&#43;
PROB:ditch
*/#includeconst int MAXV &#61; 205;
const int MAXC &#61; 1e7 &#43; 5;int m, n;
int c[MAXV][MAXV];
bool vis[MAXV];
int ans;int min(int a, int b) {return (a }void init() {scanf("%d%d", &m, &n);for(int i &#61; 0; i }int dfs(int idx, int flow) {if(idx &#61;&#61; n) return flow;for(int i &#61; 1; i <&#61; n; i&#43;&#43;) {if(vis[i]) continue;int f &#61; min(flow, c[idx][i]);if(f &#61;&#61; 0) continue;vis[i] &#61; true;int d &#61; dfs(i, f);//vis[i] &#61; false;if(d !&#61; 0) {c[idx][i] -&#61; d;c[i][idx] &#43;&#61; d;return d;}}return 0;
}void solve() {while(true) {for(int i &#61; 1; i <&#61; n; i&#43;&#43;) vis[i] &#61; false;vis[1] &#61; true;int delta &#61; dfs(1, MAXC);if(delta &#61;&#61; 0) break;ans &#43;&#61; delta;}printf("%d\n", ans);
}int main() {freopen("ditch.in", "r", stdin);freopen("ditch.out", "w", stdout);init(); solve();return 0;
}




推荐阅读
  • 在对WordPress Duplicator插件0.4.4版本的安全评估中,发现其存在跨站脚本(XSS)攻击漏洞。此漏洞可能被利用进行恶意操作,建议用户及时更新至最新版本以确保系统安全。测试方法仅限于安全研究和教学目的,使用时需自行承担风险。漏洞编号:HTB23162。 ... [详细]
  • Java Socket 关键参数详解与优化建议
    Java Socket 的 API 虽然被广泛使用,但其关键参数的用途却鲜为人知。本文详细解析了 Java Socket 中的重要参数,如 backlog 参数,它用于控制服务器等待连接请求的队列长度。此外,还探讨了其他参数如 SO_TIMEOUT、SO_REUSEADDR 等的配置方法及其对性能的影响,并提供了优化建议,帮助开发者提升网络通信的稳定性和效率。 ... [详细]
  • 在Android平台中,播放音频的采样率通常固定为44.1kHz,而录音的采样率则固定为8kHz。为了确保音频设备的正常工作,底层驱动必须预先设定这些固定的采样率。当上层应用提供的采样率与这些预设值不匹配时,需要通过重采样(resample)技术来调整采样率,以保证音频数据的正确处理和传输。本文将详细探讨FFMpeg在音频处理中的基础理论及重采样技术的应用。 ... [详细]
  • 如何撰写适应变化的高效代码:策略与实践
    编写高质量且适应变化的代码是每位程序员的追求。优质代码的关键在于其可维护性和可扩展性。本文将从面向对象编程的角度出发,探讨实现这一目标的具体策略与实践方法,帮助开发者提升代码效率和灵活性。 ... [详细]
  • [c++基础]STL
    cppfig15_10.cppincludeincludeusingnamespacestd;templatevoidprintVector(constvector&integer ... [详细]
  • MicrosoftDeploymentToolkit2010部署培训实验手册V1.0目录实验环境说明3实验环境虚拟机使用信息3注意:4实验手册正文说 ... [详细]
  • 本文介绍如何使用 Python 的 DOM 和 SAX 方法解析 XML 文件,并通过示例展示了如何动态创建数据库表和处理大量数据的实时插入。 ... [详细]
  • 本文对比了杜甫《喜晴》的两种英文翻译版本:a. Pleased with Sunny Weather 和 b. Rejoicing in Clearing Weather。a 版由 alexcwlin 翻译并经 Adam Lam 编辑,b 版则由哈佛大学的宇文所安教授 (Prof. Stephen Owen) 翻译。 ... [详细]
  • 基于Linux开源VOIP系统LinPhone[四]
    ****************************************************************************************** ... [详细]
  • 本文将详细介绍如何在Mac上安装Jupyter Notebook,并提供一些常见的问题解决方法。通过这些步骤,您将能够顺利地在Mac上运行Jupyter Notebook。 ... [详细]
  • 如何将Python与Excel高效结合:常用操作技巧解析
    本文深入探讨了如何将Python与Excel高效结合,涵盖了一系列实用的操作技巧。文章内容详尽,步骤清晰,注重细节处理,旨在帮助读者掌握Python与Excel之间的无缝对接方法,提升数据处理效率。 ... [详细]
  • Android 构建基础流程详解
    Android 构建基础流程详解 ... [详细]
  • 本文详细解析了使用C++实现的键盘输入记录程序的源代码,该程序在Windows应用程序开发中具有很高的实用价值。键盘记录功能不仅在远程控制软件中广泛应用,还为开发者提供了强大的调试和监控工具。通过具体实例,本文深入探讨了C++键盘记录程序的设计与实现,适合需要相关技术的开发者参考。 ... [详细]
  • 本文介绍了如何利用Shell脚本高效地部署MHA(MySQL High Availability)高可用集群。通过详细的脚本编写和配置示例,展示了自动化部署过程中的关键步骤和注意事项。该方法不仅简化了集群的部署流程,还提高了系统的稳定性和可用性。 ... [详细]
  • 在《ChartData类详解》一文中,我们将深入探讨 MPAndroidChart 中的 ChartData 类。本文将详细介绍如何设置图表颜色(Setting Colors)以及如何格式化数据值(Formatting Data Values),通过 ValueFormatter 的使用来提升图表的可读性和美观度。此外,我们还将介绍一些高级配置选项,帮助开发者更好地定制和优化图表展示效果。 ... [详细]
author-avatar
伤心的海2012_626
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有