Euler Circuit
Time Limit: 3000MS
Memory Limit: Unknown
64bit IO Format: %lld & %llu
[Submit] [Go Back] [Status]
Description
Problem D
EulerCircuit
Input: standard input
Output: standard output
Time Limit: 2 seconds
AnEuler circuit is a graph traversal starting and ending at the same vertex andusing every edge exactly once. Finding an Euler circuit in an undirected ordirected graph is a fairly easy task, but what about graphs where some of theedges are directed and
some undirected? An undirected edge can only be traveledin one direction. However, sometimes any choice of direction for the undirectededges may not yield an Euler circuit.
Givensuch a graph, determine whether an Euler circuit exists. If so, output such acircuit in the format specified below. You can assume that the underlyingundirected graph is connected.
Input
The first line in the inputcontains the number of test cases, at most 20.Each test case starts with a line containing two numbers,
Vand E:the number of vertices (1 <= V <= 100) andedges (1<=
E <= 500) in the graph. The verticesare numbered from 1 to V.Then follows
Elines specifying the edges. Each such line will be in the format a b typewhere
aand bare two integers specifying the endpoints of the edge.
type will eitherbe the character 'U',if the edge is undirected, or 'D', if the edge is directed. Inthe latter case, the edge starts at
a andends at b.
Output
If anEuler circuit exist, output an order in which the vertices can be traversed ona single line. The vertex numbers should be delimited with a single space, andthe start and end vertex should be included both at the beginning and the endof the sequence.
Since most graphs have multiple solutions, any valid solutionwill be accepted. If no solution exist, output the line "No euler circuitexist". Output a blank line between each test case.
Sample Input Output for Sample Input
2
6 8
1 3 U
1 4 U
2 4 U
2 5 D
3 4 D
4 5 U
5 6 D
5 6 U
4 4
1 2 D
1 4 D
2 3 U
3 4 U
1 3 4 2 5 6 5 4 1
No euler circuit exist
歐拉回路的判定與前面的方法一樣,關鍵是路徑輸出問題,跑最大流之後,流量不為0的邊就是需要改變的邊,
忘記清空數組導致wa糾結了一下午。
代碼:
#pragma comment(linker, "/STACK:102400000,102400000")
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include