(with Tuola loop solution) POJ 2230

Source: Internet
Author: User

Watchcow
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 6255 Accepted: 2708 Special Judge

Description

Bessie ' s been appointed the new Watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoers is doing any evil. She begins at the barn, makes his patrol, and then returns to the barn when she's done.

If She were a more observant cow, she might being able to just walk each of M (1 <= M <= 50,000) bidirectional trails N Umbered 1..M between N (2 <= n <=) fields numbered 1..N on the farm once and is confident that she ' s seen Eve Rything she needs to see. But since she is ' t, she wants to make sure she walks down each trail exactly twice. It's also important that she's the trips along each trail is in opposite directions, so, she doesn ' t miss the same thing Twice.

A pair of fields might is connected by more than one trail. Find a path that Bessie can follow which would meet her requirements. Such a path is guaranteed to exist.

Input

* Line 1:two integers, N and M.

* Lines 2..m+1:two integers denoting a pair of fields connected by a path.

Output

* Lines 1..2m+1:a List of fields she passes through, one per line, beginning and ending with the Barn at Field 1. If more than one solution are possible, output any solution.

Sample Input

4 51 21 42 32 43 4

Sample Output

12342143241

Hint

OUTPUT DETAILS:

Bessie starts at 1 (barn), goes to 2, then 3, etc ...
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath > #include <cstdlib> #include <algorithm> #include <queue> #include <vector> #include < Stack>using namespace Std;int n,m;vector<int> e[10010];bool vis[10010];void dfs (int u) {for    (int i=0;i< E[u].size (); i++)    {        int v=e[u][i];        if (v!=-1)        {            e[u][i]=-1;            DFS (v);        }    }    printf ("%d\n", U);} int main () {    int x, y;    memset (vis,0,sizeof (Vis));    scanf ("%d%d", &n,&m);    for (int i=0;i<m;i++)    {        scanf ("%d%d", &x,&y);        E[x].push_back (y);        E[y].push_back (x);    }    DFS (1);    return 0;}

  

(with Tuola loop solution) POJ 2230

Related Article

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.