views:

164

answers:

2

Consider the following game on an undirected graph G. There are two players, a red color player R and a blue color player B. Initially all edges of G are uncolored. The two players alternately color an uncolored edge of G with their color until all edges are colored. The goal of B is that in the end, the blue-colored edges form a connected spanning subgraph of G. A connected spanning subgraph of G is a connected subgraph that contains all the vertexes of graph G. The goal of R is to prevent B from achieving his goal.

Assume that R starts the game. Suppose that both players play in the smartest way. Your task is to find out whether B will win the game.

Input: Each test case begins with a line of two integers n ( 1 <= n <= 10) and m (0 <= m <= 30), indicating the number of vertexes and edges in the graph. All vertexes are numbered from 0 to n-1. Then m lines follow. Each line contains two integers p and q ( 0 <= p, q < n) , indicating there is an edge between vertex p and vertex q.

Output: For each test case print a line which is either "YES" or "NO" indicating B will win the game or not.

Example:

3 4

0 1

1 2

2 0

0 2

Output: Yes

My idea: If we can find two disjoint spanning trees of the graph, then player B wins the game. Otherwise, A wins. 'Two disjoint spanning trees' means the edge sets of the two trees are disjoint

I wonder if you can prove or disprove my idea

A: 

So I think R should follow the following strategy:

Find the node with least degree (uncolored edges) (which does not have any Blue colored Edge)
call it N
if degree of N (uncolored edges) is 1 then R wins, bye bye
Find its adjacent nodes {N1,...,Nk}
Pick up M from {N1,...,Nk} such that degree (uncolored) of M (and M does not have any blue colored edge) is the least among the set
Color the edge Connecting from M to N
Repeat this.

bhups
How do you find out whether your strategy wins for a given game? The question wants to know if B has a winning strategy.
Charles Stewart
So this is strategy for R to win, which means if R is loosing then B is winning and vice versa.
bhups
`if degree of N (uncolored edges) is 1 then R wins, bye bye` why does R win in this case? B can just choose other nodes that keep his subgraph connected.
IVlad
It's not a winning strategy for R: consider two triangles with vertices labelled ABC where there are two edges on arc AB, and one edge on the arc BC, and one triangle has one edge on AC, the other two. Copy this and join the two triangles by an edge between their A vertices. R has a winning strategy by disconnecting the two triangles: your algorithm dictates not doing this, and B has a winning strategy against your algorithm.
Charles Stewart
@IVlad: N does not have any blue colored edge (according to first line), And later if degree of N (uncolored edge) is 1 then R can simply color it to Red, then this node cannot have a Blue Color edge which will keep it out of the Final subgraph. Hence Red wins.
bhups
@Charles: Agreed! Then probably, use of minimax might be useful here. And the heuristic can be the number of connected subgraphs which have all the nodes.any thoughts???
bhups
The general point is that, having an algorithm that *would* win whenever winning was possible would be a nice thing, but the question wants you to say when winning is possible. Take, e.g., two vertices with two edges between them. It's as clear how to apply your algorithm in this certain-to-lose case as it is in the certain-to-win case with one edge between them.
Charles Stewart
Reasoning about graphs is hard. I could think up metrics for a minimax algorithm, but I'd find it hard to convince myself that there wasn't a case where R's winning strategy didn't involve going uphill against the metric. My thoughts lie in the direction of brute force.
Charles Stewart
One more approach I can think of using some "min-cut" algorithms. R can keep looking for "min-cut" and coloring the edges and Blue will then wants to avoid this.
bhups
+3  A: 

Your idea is correct. Find a proof here: http://www.cadmo.ethz.ch/education/lectures/FS08/graph_algo/solution01.pdf

If you search for "connectivity game" or "maker breaker games" you should find some more interesting problems and algorithms.

Ben Schwehn
Thx. But I want to know how to find two disjoint spanning trees of a graph
Rambo
ftp://reports.stanford.edu/pub/cstr/reports/cs/tr/74/455/CS-TR-74-455.pdf gives an algorithm based on depth first search. I only skimmed the paper, it's 40+ pages, but the algorithm itself seems fairly straightforward. Don't know if there is a simpler way to do it...
Ben Schwehn
Cf. http://stackoverflow.com/questions/3271763/how-to-find-two-disjoint-spanning-trees-of-an-undirected-graph
Charles Stewart
Thx. But that paper presents an algorithm for finding two edge-disjoint spanning trees rooted at a fixed vertex of a directed graph.But this problem deals with undirected graph. I don't know if it can work
Rambo
Oh, sorry. I was trying to link to this paper: http://www.springerlink.com/index/K5633403J221763P.pdf but a) springer seems down and b) don't know if what subscription if any you would need to access it online. I think the link I gave as a replacment is indeed only for directed graphs. I'm pretty sure the other tarjan paper (springer link above) concerns undirected graphs (but obviously can't check now with springer being down)
Ben Schwehn
actually both papers might only consider DAGs. Sorry for being a bit useless :)
Ben Schwehn
I guess you could simply find all spanning trees and then pairwise check for disjointness (eg Gabow and Myers 1978). Would be interested to know if there is a more efficient way?
Ben Schwehn
Here is my naive solution:First we use dfs to generate a spanning tree. If the graph does not have a spanning tree, then B loses the game. Then we can find another spanning tree from the remaining graph.We enumerate a edge in the current spanning tree and a edge in the remaining graph and exchange them. Check if the current spanning tree is connected, and check a certain connected component of the subgraph has more vertexes. If so, we dfs next level, until there is a new spanning tree found.
Rambo
I think we can use union-find set to maintain the connectivity of the vertexes
Rambo
Cool, have you implemented it already? How fast is it in real life? I guess you made sure that this finds a set every time there is one independent of the spanning tree you're starting with. This was not immediately obvious to me (but I'm not too good with graph theory anyway...)
Ben Schwehn
Yeah, I've done it. I am sure this method will be extremely slow for large graph
Rambo