poj1909 Marbles on a tree
来源:互联网 发布:ubuntu安装libcurl 编辑:程序博客网 时间:2024/06/17 22:01
一看就会
#include <iostream>#include <cstdio>#include <cmath>#include <cstring>#include <vector>using namespace std;const int M = 10005;vector<int>que[M];int num[M];int rd[M];int n, ans;void init() { for(int i = 0; i <= n; i++){ que[i].clear(); num[i] = 0; rd[i] = 0; }}void dfs(int u){ int v; for(int i = 0; i < (int)que[u].size(); i++) { v = que[u][i]; dfs(v); num[u] += num[v]; ans += fabs(num[v]); } num[u] -= 1;}int main(){ int a, b, q; while(scanf("%d", &n) != EOF) { if(!n) break; init(); ans = 0; for(int i = 0; i< n; i++){ scanf("%d%d%d", &a, &b, &q); num[a] = b; for(int j = 0; j < q; j++){ scanf("%d", &b); que[a].push_back(b); rd[b]++; } } for(int i = 1; i <= n; i++){ if(!rd[i]){ dfs(i); break; } } printf("%d\n", ans); } return 0;}
0 0
- poj1909 Marbles on a tree
- UVa10672 - Marbles on a tree(BFS)
- ZOJ 2374 Marbles on a tree
- POJ 1909 Marbles on a tree 笔记
- pku 1909 Marbles on a tree(我都不知道这能不能算DP)
- A - Marbles
- poj1909
- spoj375Query on a tree
- Query on A Tree
- 3019. A Game with Marbles
- Marbles
- 3804 Query on a tree
- SPOJ Query on a tree
- Query on a tree II
- [SPOJ375]Query on a tree
- SPOJ375 Query on a tree
- hdu_3804_Query on a tree(树链剖分)
- SPOJ QTREEQuery on a tree
- krpano 教程 - 常用actions说明
- Arcpy 合并一个文件夹下的FileGDB
- 十三:微信公众平台开发模式启用及接口配置
- QT编程系列3--几个常用组件的使用(上)-第一个按钮的增加
- 关于Android out of memory解决办法的总结
- poj1909 Marbles on a tree
- SecureCRT配置端口映射和FileZilla工具结合使用
- Asp.Net函数大全
- doophp 常用篇
- Android FakeID(Google Bug 13678484) 漏洞详解
- POJ-2349 Arctic Network
- UVa11584 Partitioning by Palindromes
- Codeforces Round #260 (Div. 2) C. Boredom【DP】
- Java学习小试牛刀之数字金额转换为人民币大写