链接

想偷点懒用矩阵存 一直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. There is no Action mapped for namespace [/] and action name [user] associated with context path

    从c++转到java,初学struts,竟然碰到一个因写错单词而造成的错误,structs --> struts

  2. NOIP200701

    题是这样的: 试题描述 某小学最近得到了一笔赞助,打算拿出其中一部分为学习成绩优秀的前5名学生发奖学金.期末,每个学生都有3门课的成绩:语文.数学.英语.先按总分从高到低排序,如果两个同学总分相同,再 ...

  3. 2017 google Round C APAC Test 题解

    题解参考网上的答案,以及我自己的想法. 主要参考网站:http://codeforces.com/blog/entry/47181,http://codeforces.com/blog/entry/4 ...

  4. 九度OJ 1513 二进制中1的个数

    题目地址:http://ac.jobdu.com/problem.php?pid=1513 题目描述: 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 输入: 输入可能包含多个测试样 ...

  5. 【转】Windows10下80端口被PID为4的System占用导致Apache无法启动的分析与解决方案

    昨天刚更新了Windows10,总体上来说效果还是蛮不错的,然而今天在开启Apache服务器的时候却发现,Apache莫名其妙的打不开了,起初以为是权限的问题,于是使用管理员身份的控制台去调用命令ne ...

  6. css3太极图效果+自动旋转

    主要使用border-radius属性实现圆,半圆,定位坐标覆盖部分模块. 半圆: width: 50%; height: 100%; border-radius:100% 0 0 100% /50% ...

  7. PHP中0、空、null和false的总结

    php中很多人还不懂php中 0 , '' , null 和 false 之间的区别,这些区别有时会影响到数据判断的正确性和安全性,给程序的测试运行造成很多麻烦.另外在面试题中也会遇到这些问题,如下: ...

  8. Python+Bottle+Sina SAE快速构建网站

    Bottle是新生一代Python框架的代表,利用Bottle构建网站将十分简单. Sina SAE是国内较出名的云平台之一,十分适用于个人网站的开发或创业公司网站开发. 下面将介绍如果通过Pytho ...

  9. pair work-Elevator Schedule

    编程人员:周敏轩 192 周萱 149 1 有关结对编程的思考 结对编程技术是指两位程序员肩并肩地坐在同一台电脑前合作完成同一个设计.同一个算法.同一段代码或同一组测试.通过这次的结对编程练习我结识了 ...

  10. 实现strlen,strcpy,strcat,strcmp同功能的函数stringLength,stringCopy,stringCatch,stringCompare

    #import <Foundation/Foundation.h> /* 求字符串长度 */ int stringLength(char arr[]); /* 复制字符串 将arr1 复制 ...