Talk:UVa 10982 - Troublemakers

There is another greedy algorithm, which seems simpler to me: consider vertices in any order (1,2,...,n works fine); put each vertex into partition, which makes less conflicts with previous vertices.

Idea of proof: at each step, at least half of the edges which connect current vertex with previous vertices will be "split" (i.e. have endpoints in different partitions.) So, at the end, there will be at most floor(m/2) edges with endpoints in same partition.

Btw, less-than-or-equal-to sign in LaTeX is "\le". Sweepline 10:10, 28 Jan 2006 (EST)

I had actually submitted that solution (perhaps my implementation buggy) and was given a wrong answer. My concern with your proof is that a given step, you may split some edge, and then at a later step, you may unsplit it when you process the other vertex adjacent to it.

I'd be happy to have a better article here though ;).

I'll replace <= with \le, thanks.

--Rrenaud 13:05, 28 Jan 2006 (EST)

This is how I've implemented this algorithm in my accepted program: /* G[u][v] = (is there an edge (u,v) in the graph) ? 1 : 0 */

int where[128]; for (int i = 1; i &lt;= n; i++) { int a = 0, b = 0;

for (int j = 1; j &lt; i; j++) if (where[j] == 0) a += G[i][j]; else b += G[i][j];

where[i] = (a &lt;= b) ? 0 : 1; }

/* output all vertices i, such that where[i]==0 */

Edges can't be unsplit again, because once the algorithm has chosen a partition for some vertex, that vertex will stay in that partition till the end. Edges could be unsplit only if vertices could change partitions.

Let $$E_i$$ denote subset of edges (i,j) in which j<i. $$E_1,\dots,E_n$$ are disjoint sets, whose union is E (all edges). At the i-th step the above code considers only edges of $$E_i$$. Variables a and b are the number of edges, which connect i-th vertex with vertices in 1st and 2nd partition respectively. The number of unsplit edges in $$E_i$$ after i-th step is: $$\min(a,b) \le {|E_i| \over 2}$$, because $$a+b=|E_i|$$.

And the total number on unsplit edges is bounded by: $$\sum_{i=1}^n {|E_i| \over 2} \le {m \over 2}$$.

Sweepline 17:20, 28 Jan 2006 (EST)

I am convinced, I think your solution is indeed clearer. I think you should replace my solution with yours. --Rrenaud 18:23, 28 Jan 2006 (EST)