题目链接

求出最长路.....

 #include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 1e6+;
int head[maxn], dis[], num, val[];
struct node
{
int to, nextt, c;
}e[maxn];
void add(int u, int v, int c) {
e[num].to = v;
e[num].nextt = head[u];
e[num].c = c;
head[u] = num++;
}
void init() {
mem1(dis);
mem1(head);
num = ;
}
int dfs(int u) {
if(~dis[u])
return dis[u];
int ret = val[u], ans = ;
for(int i = head[u]; ~i; i = e[i].nextt) {
int v = e[i].to;
ans = max(ans, dfs(v));
}
return dis[u] = ans+ret;
}
int main()
{
int n, x, y;
while(cin>>n) {
init();
for(int i = ; i<=n; i++) {
scanf("%d", &val[i]);
scanf("%d", &x);
while(x--) {
scanf("%d", &y);
add(y, i, val[i]);
}
}
for(int i = ; i<=n; i++) {
if(dis[i]==-) {
dis[i] = dfs(i);
}
}
int ans = ;
for(int i = ; i<=n; i++) {
ans = max(ans, dis[i]);
}
printf("%d\n", ans);
}
return ;
}

poj 1949 Chores 最长路的更多相关文章

  1. POJ 1949 Chores(DAG上的最长路 , DP)

    题意: 给定n项任务, 每项任务的完成用时t和完成每项任务前需要的k项任务, 求把所有任务完成的最短时间,有当前时间多项任务都可完成, 那么可以同时进行. 分析: 这题关键就是每项任务都会有先决条件, ...

  2. POJ 1949 Chores (很难想到的dp)

    传送门: http://poj.org/problem?id=1949 Chores Time Limit: 3000MS   Memory Limit: 30000K Total Submissio ...

  3. poj 2253 Frogger (最长路中的最短路)

    链接:poj 2253 题意:给出青蛙A,B和若干石头的坐标,现青蛙A想到青蛙B那,A可通过随意石头到达B, 问从A到B多条路径中的最长边中的最短距离 分析:这题是最短路的变形,曾经求的是路径总长的最 ...

  4. POJ 1949 Chores

    Farmer John's family pitches in with the chores during milking, doing all the chores as quickly as p ...

  5. POJ 2472 106 miles to Chicago(Dijstra变形——史上最坑的最长路问题)

    题目链接 :http://poj.org/problem?id=2472 Description In the movie "Blues Brothers", the orphan ...

  6. poj 3592 Instantaneous Transference 缩点+最长路

    题目链接 给一个n*m的图, 从0, 0这个点开始走,只能向右和向下. 图中有的格子有值, 求能获得的最大值. 其中有些格子可以传送到另外的格子, 有些格子不可以走. 将图中的每一个格子都看成一个点, ...

  7. POJ.1752.Advertisement(差分约束 最长路SPFA)

    题目链接 \(Description\) 有\(n\)个人在一条直线上跑步,每个人的起点 \(Si\).终点 \(Ei\) 已知:每个点可以放一个广告牌,一个人\(i\)能看到的广告牌数量为 \(Ei ...

  8. poj 1932 XYZZY(spfa最长路+判断正环+floyd求传递闭包)

    XYZZY Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 4154   Accepted: 1185 Description ...

  9. POJ 3126 --Father Christmas flymouse【scc缩点构图 &amp;&amp; SPFA求最长路】

    Father Christmas flymouse Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 3007   Accep ...

随机推荐

  1. java反射入门

    http://www.cnblogs.com/rollenholt/archive/2011/09/02/2163758.html package reflectTest; class Demo{ / ...

  2. 开发环境配置--Ubuntu+Qt4+OpenCV(二)

    同系列文章 1. 开发环境配置--Ubuntu+Qt4+OpenCV(一) 2. 开发环境配置--Ubuntu+Qt4+OpenCV(二) 3. 开发环境配置--Ubuntu+Qt4+OpenCV(三 ...

  3. windows server 2008 NTP授时服务[转]

    转自  http://www.cnblogs.com/jingdian1956/admin/EditPosts.aspx?opt=1 服务端: 默认情况下,独立服务器WINDOWS SERVER 20 ...

  4. 判断浏览器 IE 11

    var getOs=function()  {   try {  var u = window.navigator.userAgent.toLocaleLowerCase(),  msie = /(m ...

  5. Extjs Store 的用法详解

    Ext.data.Store的基本用法 在使用之前,首先要创建一个Ext.data.Store的实例,如下面的代码所示.       每个store最少需要两个组件的支持,分别是proxy和reade ...

  6. background:url 的使用方法

    #pingfen li{ width:27px; float:left; height:28px; cursor:pointer; background:url( ; list-style:none; ...

  7. ios字符串计算高度总结

    1.用xib的话,设置约束的时候 不设置lable的高度即可,高度返回的就是最优高度. 2.用lable代码计算高度 CGFloat getHeightForLableString(NSString ...

  8. 翻译 GITHUB上HOW TO BE A GOOD PROGRAMMER

    转载请注明出处: http://www.cnblogs.com/hellocwh/p/5184072.html 更多内容点击查看 https://ahangchen.gitbooks.io/windy ...

  9. 不同的strcmp

    Android libc中的strcmp https://android.googlesource.com/platform/bootable/bootloader/legacy/+/donut-re ...

  10. A类型物料必须为装配拉式,供应子库为B仓

    应用 Oracle Bill Of   Materiel 层 Level Function 函数名 Funcgtion Name MT_BOMFDBOM 表单名 Form Name BOMFDBOM ...