Page 1 of 1

### 12348 - Fun Coloring

Posted: Wed Jul 17, 2013 1:33 pm
Can't understand the problem ...
very poor description Please someone explain what the problem actually said ....
at least one member of each Si is assigned a different color from the other members
what does it mean ?

### Re: 12348 - Fun Coloring

Posted: Wed Jul 17, 2013 10:20 pm
You need to see if you can assign a color (R or B) to each integer 1 through n such that none of the m sets contain only one color. For the first sample input you could assign:
1=R, 2=R, 3=B, 4=R, 5=R

1R 2R 3B
2R 3B 4R
1R 3B 5R

For the second sample input if you assign 1=R, then 2 and 3 must be B, but 2 and 3 are in a set together and that set is all B so it isn't possible to fun color.
1R 2B
1R 3B
2B 3B

### Re: 12348 - Fun Coloring

Posted: Thu Jul 18, 2013 1:47 am
Thanks brianfry713 for quick reply Now i get the problem This problem made me crazy .....

### Re: 12348 - Fun Coloring

Posted: Thu Jul 18, 2013 3:31 am
Careful !!! There shouldn't be any newline in the output .. it will cost WA ### Re: 12348 - Fun Coloring

Posted: Wed Jul 06, 2016 12:05 am
Can someone help me please? I have got a lot of WA and I don't know why. I have tried various solutions and no one worked. This is the most straightforward one (though not optimal) but it is WA. I will appreciate any help. Thanks!

Code: Select all

``````import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class B {

static int N, M;
static Set[] sets;

public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);

int tc = Integer.parseInt(sc.nextLine());
while(tc-->0)
{
StringTokenizer st = new StringTokenizer(sc.nextLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
sets = new Set[M];

for(int i = 0; i < M; ++i)
{
st = new StringTokenizer(sc.nextLine());
Set s = new Set();
while(st.hasMoreTokens())
s.x.add(Integer.parseInt(st.nextToken()) - 1);
sets[i] = s;
}

boolean possible = false;
for(long i = 0; !possible && i < 1l<<N; ++i)
{
boolean can = true;
for(Set s: sets)
{
if(s.x.size() == 3)
{
long sum = ((i>>s.x.get(0))&1) + ((i>>s.x.get(1))&1) + ((i>>s.x.get(2))&1);
if(sum <= 0 || sum >= 3)
can = false;
}
else
if(s.x.size() == 2)
{
long sum = ((i>>s.x.get(0))&1) + ((i>>s.x.get(1))&1);
if(sum != 1)
can = false;
}
else
can = false;
if(!can)
break;
}
possible |= can;
}
System.out.print(possible?'Y':'N');
if(tc != 0)
sc.nextLine();
}

out.flush();
out.close();
}

static class Set { ArrayList<Integer> x = new ArrayList<Integer>(); }

static class Scanner
{
StringTokenizer st;
BufferedReader br;

public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}

public int nextInt() throws IOException {return Integer.parseInt(next());}

public long nextLong() throws IOException {return Long.parseLong(next());}

public String nextLine() throws IOException {return br.readLine();}

public double nextDouble() throws IOException { return Double.parseDouble(next()); }

public boolean ready() throws IOException {return br.ready();}
}
}
``````

### Re: 12348 - Fun Coloring

Posted: Fri Apr 20, 2018 9:57 am
It is most likely there are some bugs in judge program. I sent an email to administrator two weeks ago but no reply.