2017.07.05NOIP Improvement Group A group A postman

Source: Internet
Author: User
Description

The Post office needs you to help them to design a postman to go through all the villages and trails in the faraway countryside at least once (the input data will guarantee that such a path must exist).
However, there is a cost for each route. Villagers in various villages hope that the sooner the postman arrives in their village, the better. As a result, people in various villages have adopted measures: Suppose village I is the first k different village where the postman arrives on his mailing route. If K<=w (i), then the villagers in this village will pay the Post Office W (i)-k euros. Of course, if k>w (i), the Post Office also agreed to pay k-w (i) euros to the village, repeated through the village do not repeat the charges. In addition, the post office will pay the postman 1 euros as a subsidy for every passing path.
There are now n villages, numbered 1 to N in turn. The post office is located in village No. 1th, so the postman's route starts here and ends in the village. The number of intersections that can leave each village must be 2,4 or 8. This allows the presence of multiple paths between the same villages, or a path that constitutes a self-loop.
Your task is to design a route that makes the post office make the most money (or the least amount of money). If there are multiple optimal solutions, the output dictionary order is minimal. Input

The first line: two integer n,m, respectively, indicating the number of villages and the number of trails.
Next n lines, one integer per line: w (i) (1≤w (i) <1 000)
Next m line, two integers per line u,v, indicates the number of the village to which this path is connected. Output

First line: An integer k, the length of the path your program has designed
Second line: k+1 integer, v1,v2...vk+l, each number separated by a space, indicating the number of the village you have designed the path to, which needs to meet V1=vk+1=1 Sample Input

6 7
1
7
4
10
20
5
2 4
L 5
2 L
4 5
3 6
1 6
1 3 Sample Output

7
1 2 4 5 1 3 6 1 Solution

When you read the title, you will find that the N-W value entered at the beginning is not used
So the question is, let's ask you to ask for the smallest Euler loop.
It is clear that a Euler circuit is removed from a Euler circuit or a Euler circuit
Well, there will be a lot of Euler loops that use the same point and go straight from each point to find the shortest path.
My language is too poor, can point here has the great God detailed explanation Code

 #include <cstdio> #include <algorithm> #include <cstring> #define FO (i,a,b
) for (int i=a;i<=b;i++) #define N, using namespace std;
int n,m,wy,a[n][n],s[n*10];
        void dg (int x) {fo (i,1,n) if (A[x][i]) {a[x][i]--;a[i][x]--;
    DG (i);
} s[++s[0]]=x;
    } int main () {scanf ("%d%d", &n,&m);
    Fo (i,1,n) scanf ("%d", &wy);
        Fo (i,1,m) {int x,y;scanf ("%d%d", &x,&y);
    a[x][y]++;a[y][x]++;
    } printf ("%d\n", m);
    DG (1); for (; s[0];s[0]--) printf ("%d", s[s[0]]);} 

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.