链接

想偷点懒用矩阵存 一直WA 后来看讨论说有重边改为邻接表 这题边可能走了不止一次 我设的最多两次可过

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define INF 0xfffffff
struct node
{
int u,v,w1,w2,d,next;
}ed[];
int head[];
int n,m,p[][],ans;
int vis[],t;
void init()
{
t = ;
memset(head,-,sizeof(head));
}
void add(int u,int v,int w1,int w2,int d)
{
ed[t].u = u;
ed[t].v = v;
ed[t].w1 = w1;
ed[t].w2 = w2;
ed[t].d = d;
ed[t].next = head[u];
head[u] = t++;
}
void dfs(int u,int sum)
{
int i,s=sum;
if(sum>ans)
return ;
if(u==n)
{
ans = sum;
return ;
}
for(i = head[u] ; i!= -; i = ed[i].next)
{
int v = ed[i].v;
int tt = vis[v];
if(p[u][v]<)
{
vis[v] = ;
p[u][v]++;
if(ed[i].d==u||ed[i].d==i||vis[ed[i].d])
{
sum+=min(ed[i].w1,ed[i].w2);
}
else
{
sum+=ed[i].w2;
}
dfs(v,sum);
sum = s;
p[u][v]--;
vis[v] = tt;
}
}
}
int main()
{
int a,b,c,pp,r;
while(scanf("%d%d",&n,&m)!=EOF)
{
init();
memset(vis,,sizeof(vis));
memset(p,,sizeof(p));
ans = INF;
while(m--)
{
scanf("%d%d%d%d%d",&a,&b,&c,&pp,&r);
add(a,b,pp,r,c);
}
vis[] = ;
dfs(,);
if(ans!=INF)
printf("%d\n",ans);
else
puts("impossible");
}
return ;
}

poj3411Paid Roads(dfs)的更多相关文章

  1. Codeforces Round #369 (Div. 2) D. Directed Roads dfs求某个联通块的在环上的点的数量

    D. Directed Roads   ZS the Coder and Chris the Baboon has explored Udayland for quite some time. The ...

  2. CodeForces #369 div2 D Directed Roads DFS

    题目链接:D Directed Roads 题意:给出n个点和n条边,n条边一定都是从1~n点出发的有向边.这个图被认为是有环的,现在问你有多少个边的set,满足对这个set里的所有边恰好反转一次(方 ...

  3. codeforces 711D D. Directed Roads(dfs)

    题目链接: D. Directed Roads time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. Codeforces Round #369 (Div. 2) D. Directed Roads (DFS)

    D. Directed Roads time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. csu 1930 roads(DFS)

    Description Once upon a time there was a strange kingdom, the kingdom had n cities which were connec ...

  6. Codeforces Round #369 (Div. 2) D. Directed Roads —— DFS找环 + 快速幂

    题目链接:http://codeforces.com/problemset/problem/711/D D. Directed Roads time limit per test 2 seconds ...

  7. lightoj 1049 - One Way Roads(dfs)

    Time Limit: 0.5 second(s) Memory Limit: 32 MB Nowadays the one-way traffic is introduced all over th ...

  8. POJ 3411 Paid Roads(DFS)

    题目链接 点和边 都很少,确定一个界限,爆搜即可.判断点到达注意一下,如果之前已经到了,就不用回溯了,如果之前没到过,要回溯. #include <cstring> #include &l ...

  9. Codeforces 711 D. Directed Roads (DFS判环)

    题目链接:http://codeforces.com/problemset/problem/711/D 给你一个n个节点n条边的有向图,可以把一条边反向,现在问有多少种方式可以使这个图没有环. 每个连 ...

随机推荐

  1. [译]当你在浏览器输入url后发生了什么

    面试题会经常问这个,之前也被问过,回答的不是很好,后来看到百度前端的一篇博客,啰嗦了好多,很么触摸屏都上了..后来看到stackoverflow上的一个回答,比较短. 原文地址:http://stac ...

  2. [cocos2d-x 2.0.4][iOS7]图片加载错误

    本篇文章由:http://www.sollyu.com/cocos2d-x-2-0-4-ios7-image-loading-errors/ 说明 错误提示 <Error>: CGBitm ...

  3. win/linux 下使用 psutil 获取进程 CPU / memory / IO 占用信息

    psutil - A cross-platform process and system utilities module for Python 1. 安装 pip 安装即可. windows 下需要 ...

  4. C# 实体model验证输出

    新建Model实体: [Required(ErrorMessage = @"地址 1 为必填项!")] [StringLength(, ErrorMessage = @" ...

  5. TeeChart 的应用

    TeeChart 是一个很棒的绘图控件,不过由于里面没有注释,网上相关的资料也很少,所以在应用的时候只能是一点点的试.为了防止以后用到的时候忘记,我就把自己用到的东西都记录下来,以便以后使用的时候查询 ...

  6. 使用curl获取网站的http的状态码

    发布:thebaby   来源:net     [大 中 小] 本文分享一例shell脚本,一个使用curl命令获取网站的httpd状态码的例子,有需要的朋友参考下.本文转自:http://www.j ...

  7. Android分类前言

    柚子园项目搁置后,半年多时间里都在开发微信公众平台和在公司实习,用的都是python,django,bottle,已经很久没有开发android了.技术的东西,不用就容易生疏甚至忘掉.刚好现在需要写毕 ...

  8. FontDialog组件设置字体

    1.设置字体 private void button3_Click(object sender, EventArgs e) { this.fontDialog1.ShowDialog(); this. ...

  9. 一步步学习ASP.NET MVC3 (6)——@helper,@functions

    请注明转载地址:http://www.cnblogs.com/arhat 在前一章中,我们讲述了View如何从Action中获得数据,并显示出来,但随着需求的变化,我们可能要对View中显示的数据作出 ...

  10. windows8.1专业中文版一个可用的密钥分享

    分享一个windows8.1专业中文版一个可用的密钥,亲测可用,联网输入密钥激活即可. PKHMN-TWQ6R-XDTH7-P4WW4-YR9T7