XTU 1245 Hamiltonian Path
$2016$长城信息杯中国大学生程序设计竞赛中南邀请赛$C$题
简单题。
注意题目中给出的数据范围:$1 \le ai < bi \le n$,说明这是一个有向无环图,并且哈密顿路一定是$1 \to 2 \to 3 \to \cdots \cdots \to n$。
因此这题就很简单了。哎,明明知道这原本是一个$NP$问题,但在比赛的时候还在不停的想怎么做,没有考虑到数据给出了这样的范围.....真是菜。最后还是机智的队友发现了。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-; const int maxn=;
int n,m;
LL a[maxn]; int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(a,-,sizeof a);
for(int i=;i<=m;i++)
{
int u,v; LL w; scanf("%d%d%lld",&u,&v,&w);
if(u!=v-) continue;
if(a[v]==-) a[v]=w;
else a[v]=min(a[v],w);
}
bool fail=;
for(int i=;i<=n;i++) if(a[i]==-) fail=;
if(fail) printf("-1\n");
else
{
LL sum=;
for(int i=;i<=n;i++) sum=sum+a[i];
printf("%d\n",sum);
}
}
return ;
}
XTU 1245 Hamiltonian Path的更多相关文章
- 湘潭邀请赛 Hamiltonian Path
		
湘潭邀请赛的C题,哈密顿路径,边为有向且给定的所有边起点小于终点,怎么感觉是脑筋急转弯? 以后一定要牢记思维活跃一点,把复杂的事情尽量简单化而不是简单的事情复杂化. #include<cstdi ...
 - Android使用静默安装时碰见的问题
		
升级时碰见的异常 private void installPackage(String appName,final File apk) { if (!apk.exists()) { setHasNew ...
 - 北京地铁站点遍历最少经站次数问题普遍意义上是一个NP问题,目前不存在多项式时间算法能够解决该问题
		
http://www.cnblogs.com/jiel/p/5852591.html 众所周知求一个图的哈密顿回路是一个NPC问题: In the mathematical field of grap ...
 - codeforces 577E E. Points on Plane(构造+分块)
		
题目链接: E. Points on Plane time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
 - Codeforces Round #319 (Div. 1) C. Points on Plane 分块
		
C. Points on Plane Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/576/pro ...
 - hdu 5424 Rikka with Graph II(dfs+哈密顿路径)
		
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so h ...
 - Graph图总结
		
将COMP20003中关于Graph的内容进行总结,内容来自COMP20003,中文术语并不准确,以英文为准. Graph G = {V, E} 顶Vertices V: can contain in ...
 - List of NP-complete problems
		
This is a list of some of the more commonly known problems that are NP-complete when expressed as de ...
 - NPC问题及其解决方法(回溯法、动态规划、贪心法、深度优先遍历)
		
NP问题(Non-deterministic Polynomial ):多项式复杂程度的非确定性问题,这些问题无法根据公式直接地计算出来.比如,找大质数的问题(有没有一个公式,你一套公式,就可以一步步 ...
 
随机推荐
- 流媒体:V4L2视频获取
			
从深圳回来已经20多天了,除了完善毕业设计程序和论文,其他时间都去玩游戏了.真的是最后的一段时间能够无忧无虑在校园里挥霍自己的青春了.今天完成的答辩,比想象的要简单,一直以来想把我现在的这个流媒体的东 ...
 - UIWebView的探索
			
UIWebView 说到iOS的UIWebView,应该会很快回忆起常用委托方法,异步loadRequest.stopLoading.reload方法等. 在此我总结一些容易忽略的属性和方法: 1. ...
 - Asp.net MVC4 CodeFirst 使用EFTracingProvider
			
一.关于EFTracingProvider EFTracingProvider相关信息见作者博客:关于EFTracingProvider EFTracingProvider Demo下载地址:Trac ...
 - Python之FTP多线程下载文件之多线程分块下载文件
			
Python之FTP多线程下载文件之多线程分块下载文件 Python中的ftplib模块用于对FTP的相关操作,常见的如下载,上传等.使用python从FTP下载较大的文件时,往往比较耗时,如何提高从 ...
 - mybatis3.4测试CRUD
			
导入包 H:\jar\jdbc\mysql-connector-java-5.1.13-bin.jarH:\jar\mybatis\mybatis-3.4.1\mybatis-3.4.1.jarH:\ ...
 - Centos6.3不能使用yum install安装gcc编辑器解决办法
			
mv /var/lib/rpm/__db* /tmp rpm --rebuilddb yum clean all
 - MS Sql Server 消除重复行 保留信息完整的一条 2011-11-26 13:19(QQ空间)
			
select company ,count(company) as coun into myls from mylist group by company having count(company)& ...
 - ssd可以用作redo 盘吗?
			
ssd可以用作redo 盘吗? 1.ssd有写磨损,而且ssd的写性能也不是非常好,ssd只是随机读特别好,因为 ...
 - oracle存储过程异常捕获
			
在oracle中捕获异常,通过 //sql执行 exception when others then dbms_output.putline('exception'); 其中others表示捕获未命名 ...
 - BootStrap的菜单的快速创建
			
在bootstrap的3.0版本及以上时,菜单的创建有所改变. 现在,我们只需记住3个类 dropdown open dropdown-menu. 前两个是为ul 列表的父元素用的,最后一个是给ul ...