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 ):多项式复杂程度的非确定性问题,这些问题无法根据公式直接地计算出来.比如,找大质数的问题(有没有一个公式,你一套公式,就可以一步步 ...
随机推荐
- c#计算2个字符串的相似度
直接来代码 public static float levenshtein(string str1, string str2) { //计算两个字符串的长度. int len1 = str1.Leng ...
- 模仿c的字符转整数函数 atoi
#include<stdio.h> , KInvalid}; int g_nStatus = KValid; long StrToIntCore(char *str,bool minus) ...
- Log4j、Log4j 2、Logback、SFL4J、JUL、JCL的比较
Log4j.Log4j 2.Logback.SFL4J.JUL.JCL的比较 之前就知道有好几种日志框架,但是一直都是听别人讲,在什么时候该用何种logger,哪种logger比较好……一直对Log4 ...
- MvcMovieStore mvc5.0,EF6.01
MVC 5 实例教程(MvcMovieStore 新概念版:mvc5.0,EF6.01) - 4.创建数据上下文和数据实体模型 说明:MvcMovieStore项目已经发布上线,想了解最新版本功能请登 ...
- [转]About the security content of iOS 8
Source:http://support.apple.com/kb/HT6441 For the protection of our customers, Apple does not disclo ...
- MVC几种传值方式
一,Model public class Course { public int Id { get; set; } public string Name { get; set; } } public ...
- YARN之上的大数据框架REEF:微软出品,是否值得期待?
YARN之上的大数据框架REEF:微软出品,是否值得期待? 摘要:微软即将开源大数据框架REEF,REEF运行于Hadoop新一代资源管理器YARN的上层.对于机器学习等在数据传输.任务监控和结果 ...
- WEB安全入门
WEB安全入门 信息安全基础 信息安全目标 真实性:对信息的来源进行判断,能对伪造来源的信息予以鉴别, 就是身份认证. 保密性:保证机密信息不被窃听,盗取,或窃听者不能了解信息的真实含义. 完整性:保 ...
- Python之FTP多线程下载文件之多线程分块下载文件
Python之FTP多线程下载文件之多线程分块下载文件 Python中的ftplib模块用于对FTP的相关操作,常见的如下载,上传等.使用python从FTP下载较大的文件时,往往比较耗时,如何提高从 ...
- web前端安全---读书笔记
web前端安全---读书笔记 粗略的看完了Web前端黑客技术揭秘前两章了,由于自身的前端功力不深,当然也是初涉前端的安全问题,所以实话还是有些问题看不太明白的.在豆瓣看到的这本书,名字真心有点很肥主流 ...