Hnu13247connected Caves (topology)

Source: Internet
Author: User

Connected Caves
Time limit: 2000ms, special time limit:5000ms,Memory Limit:65536KB
Total Submit Users: 6, Accepted users:5
problem 13247: Special Judge
Problem description

You're a intern at greedy Cave plundering Corporation. Your new job is for help with one of GCPC's projects:extracting valuable gemstones from a network of connected caves. The history of the project so far:

? Tom, one of the project managers, has hired Jill, a gemstone expert. She has already surveyed these caves and determined the value of all gemstones in each cave.

? Ruby, another project manager (PM), have been busy "guesstimating" a time frame, the budget and possible profits for this p Roject.

? Evelyn and Jerry (also PMs) has hired, Cave diggers and instructed them to extract the gemstones.

? The cave diggers needed equipment to extract the gemstones and transport them to the surface. So Jimmy (another PM) ordered some machines. Sadly, he did not communicate well and the cave Diggers-he bought machines that is-the-is-a-too big for the current passage ways between caves.

? To fix this, Jimmy is fired and James, his successor, have ordered a very big drilling machine, so the cave diggers can WI Den the passage ways. However, James was fearful of cutting to his salary bonus, so he bought the cheapest machine he could find. Soon, after widening the passage to the surface into Cave 1, the cave diggers found out that the new drilling Machin E is very heavy and isn't so powerful, so it can have only being used to widen a passage by that goes downwards. Once it has reached a lower cave, the It can not be carried the back up because of its weight.

? When Alice, the project manager in charge of budget planning, announced she would, ignore further Equipment.

? In a eight hour meeting discussing the problems of the project, it is decided to limit the project expenses. So, if further drilling would hurt profits or if the drilling machine reaches a cave where it can not go on, it'll just Be abandoned. Using the other machines, the cave diggers is then being able to harvest at least some of the gemstones. Afterwards, the dig site would probably is sold to another company. Ruby is already thinking on hiring her brother as a sales expert ...

This is where you are come in. Tom has hired-determine which passage ways should be widened and thereby which caves should being visited to maximize Profits. Widening a passage-requires energy, materials and so on. You have to consider these costs. You'll be given a maps of all caves and passage ways. The map was created by the cave diggers and so it should is accurate. It contains passage ways the drilling machine can handle, including the correct drilling direction. All caves in the map is reachable from cave one.


Input

The input starts with a line containing T, the number of test cases (1≤T≤10). Each test case starts with a line containing the integers:n, the number of caves, and E, the number of passage ways (1≤ N≤2 10^4; 0≤E≤10^5). The second line contains N integers v1 v2 ... vN. Videscribes the value of all gemstones in cave I (0≤vi≤10^4). Each of the next E lines contains three Integers:ae b e c e. Such a line represents one of the possible direct passage ways from Cave ae to Cave b E, widening this passage the would c OST c e (1≤a E, b e≤n; 0≤c e≤10^4). It is guaranteed that the input contains only valid digging directions, i.e. cave be'll be strictly deeper than a E. You always start from cave number 1, because the digging machine was already there and there are no caves above.


Output

Output of the lines for every test case. In the first line print both integers p and C, where P is the profit of the best possible route from top to bottom and C are The number of visited caves on this path. The second line print the IDs of those caves, ordered from top to bottom. If There is multiple solutions with optimal profit, print any.


Sample Input
31 0104 310 20 30 401 2 191 3 231 4 344 410 20 30 401 2 102 4 201 3 203 4 10
Sample Output
10 1117 21 350 31 3 4
Problem Source
GCPC 2014


Test instructions: Give n points 1~n,m edge, each point has a value, given each edge is a a-->b cost C, no ring graph, get the total value = Pass the point of value and-the cost of passing the edge. Start at point 1 and ask how much value you can get. How many points are there and what are the dots?

Problem solving: Use topological sequences to do it. The scanf function must be self-written, otherwise time out.

#include <stdio.h> #include <vector>using namespace std; #define LL intconst int N = 20005; #define INF-    600000000struct to{int v; LL c;}; LL node[n],valu[n];int fath[n],n,in[n];vector<to>tmap[n];void Init () {for (int i=1; i<=n;i++) {In[i] = 0; Node[i]=inf;    Tmap[i].clear ();    }}void Topu () {int k,to[n],id;    LL sum;    k=0;    for (int i=2;i<=n;i++) if (!in[i]) to[++k]=i;        while (k) {int s=to[k]; k--;            for (int i=0;i<tmap[s].size (); i++) {int v=tmap[s][i].v;            in[v]--;        if (in[v]==0) to[++k]=v;    }} to[++k]=1; NODE[1]=VALU[1];    Fath[1]=1;    sum=node[1],id=1;        while (k) {int s=to[k]; k--;            for (int i=0;i<tmap[s].size (); i++) {int v=tmap[s][i].v;            in[v]--;            if (in[v]==0) to[++k]=v; if (NODE[V]&LT;NODE[S]+VALU[V]-TMAP[S][I].C) Node[v]=node[s]+valu[v]-tmAp[s][i].c,fath[v]=s;        if (Sum<node[v]) sum=node[v],id=v;    }} k=0;    while (Fath[id]!=id) {to[++k]=id; Id=fath[id];    } To[++k]=id;    printf ("%d%d\n%d", sum,k,to[k]);    for (int i=k-1; i>0; i--) printf ("%d", to[i]); printf ("\ n");}    inline void scanf (int &a) {int flag=0;    Char ch;        while (Ch=getchar ()) {if (ch== '-') {flag=1;    } if (ch>= ' 0 ' &&ch<= ' 9 ') break;    } a=0;    if (flag==0) a=ch-' 0 '; while (Ch=getchar ()) {if (ch< ' 0 ' | |        Ch> ' 9 ') break;    a=a*10+ch-' 0 '; } if (flag) a=-a;}    int main () {int t,m,a,b,c;    scanf (t);        while (t--) {scanf (n);        scanf (m);        Init ();        for (int i=1;i<=n;i++) scanf (Valu[i]);        to SS;            while (m--) {scanf (a); scanf (SS.V); scanf (SS.C);            if (A==SS.V) continue;Tmap[a].push_back (ss);        in[ss.v]++;    } topu (); }}


Hnu13247connected Caves (topology)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.