链接

想偷点懒用矩阵存 一直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. .net远程连接oracle数据库不用安装oracle客户端的方法

    .net远程连接oracle数据库不用安装oracle客户端的方法步骤: 1.添加Sytem.Data.OracleClient命名空间. 2.连接时需要ConnectionString字符串,出现在 ...

  2. tomcat maxConnections和maxThreads区别

    maxConnections:与tomcat建立的最大socket连接数,默认10000(很多网上说200,实际上通过tomcat7.0.55源码查看可以知道是10000),AbstractEndpo ...

  3. EL表达式 入门

    为了使JSP写起来更加简单. 表达式语言的灵感来自于 ECMAScript 和 XPath 表达式语言,它提供了在 JSP 中简化表达式的方法. JSP EL语言定义 E L(Expression L ...

  4. IO流06_处理流

    [处理流] 处理流可以隐藏底层设备上节点流的差异,并对外提供更加方便的输入/输出的方法. 使用处理流的思路: 使用处理流来包装节点流,程序通过处理流来执行输入输出功能,让节点流与底层的I/O设备.文件 ...

  5. [PR & ML 4] [Introduction] Model Selection & The Curse of Dimension

    这两部分内容比较少,都是直觉上的例子和非正式的定义,当然这本书中绝大多数定义都是非正式的,但方便理解.后面深入之后会对这两个章节有详细的阐述.

  6. 暑假集训(3)第三弹 -----Til the Cows Come Home(Poj2387)

    题意梗概:据说母牛在产奶的时候,因为奶量太充足,希望有人帮它挤奶,它回家就很快.我们便能喝到鲜美的 牛奶,不过,贫奶季节却大不相同,它会懒洋洋的在大草原上晃来晃去的晒太阳,而不会想到马上回家,这可不 ...

  7. WTL 中CComboBoxEx显示不了的问题

    在使用WTL的CComboBoxEx时,InsertItem之后,运行程序,ComboBox显不了问题,其原因如下: I guess you want to place combo box to di ...

  8. 客户调用COM流程

    参考:COM技术内幕 DllGetClassObjecthttps://msdn.microsoft.com/en-us/library/windows/desktop/ms680760.aspx   ...

  9. 九度OJ 1283 第一个只出现一次的字符

    题目地址:http://ac.jobdu.com/problem.php?pid=1283 题目描述: 在一个字符串(1<=字符串长度<=10000,全部由大写字母组成)中找到第一个只出现 ...

  10. windows 安装 setuptools

    在python的网站上 : https://pypi.python.org/pypi/setuptools/ 查找windows,显不如下: 点击 ez_setup.py进入, 并将内容复制下来, 保 ...