D – Til the Cows Come Home
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
SubmitStatus
Description
Bessie is out in[……]
October 27, 2012 Graph Theory No comments Graph Theory
D – Til the Cows Come Home
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
SubmitStatus
Description
Bessie is out in[……]
October 27, 2012 Graph Theory No comments Graph Theory
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 20995 Accepted: 6994
Description
Bessie is out in the field and wants to get b[……]
October 27, 2012 Graph Theory No comments Graph Theory
Problem Description
Machines have once again attacked the kingdom of Xions. The kingdom of Xions has N cities and N-1 bidirectional roads. The road n[……]
October 27, 2012 Graph Theory No comments Graph Theory
Problem Description
The project West-East power transmission is famous around the world. It transmits the electricity from western areas to east Ch[……]
October 27, 2012 Graph Theory No comments Graph Theory
D – Til the Cows Come Home
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
SubmitStatus
Description
Bessie is out in[……]
October 27, 2012 Graph Theory No comments Graph Theory
B – Agri-Net
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
SubmitStatus
Description
Farmer John has been elected ma[……]
October 27, 2012 Graph Theory No comments Graph Theory
B – Agri-Net
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u
SubmitStatus
Description
Farmer John has been elected ma[……]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #define MAX 10000 using namespace std; int cnt;//0 int lastshow[MAX];//i,-1 int sum; int vis[MAX]; struct edge{ //a->b int to; //b int pro; //a int weight;// }e[MAX]; void insert(){ int a, b, weight; scanf("%d %d %d", &a, &b, &weight); e[cnt].to = b; e[cnt].pro = lastshow[a]; //a e[cnt].weight = weight; lastshow[a] = cnt ++; //lastshow } int dfs(int a){ if(vis[a]) return 0; // cout << endl << a << endl; vis[a] = 1; int ret = 0; int id = lastshow[a]; while(id != -1){ ret += e[id].weight; // cout << endl << e[id].weight << endl; ret += dfs(e[id].to); id = e[id].pro; } return ret; } int main(){ int n, c, srch; int i, j, k; while(cin >> n >> c){ cnt = 0; sum = 0; memset(vis, 0, sizeof(vis)); for(i = 0; i < MAX; i ++){ lastshow[i] = -1; } for(i = 0; i < c; i ++){ insert(); } //i while(~scanf("%d", &srch)){ if(-1 == srch) break; int id = lastshow[srch]; cout << "" << srch << ":"<<endl; while(id != -1){ cout << e[id].to << " " << e[id].weight << endl; id = e[id].pro; } } cout << "" << dfs(0) << endl; } return 0; } |
October 3, 2012 Graph Theory No comments Graph Theory
Description
Bob is very interested in the data structure of a tree. A tree is a directed graph in which a special node is singled out, called the “ro[……]