Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
Isart and Modsart were trying to solve an interesting problem when suddenly Kasra arrived. Breathless, he asked: "Can you solve a problem I'm stuck at all day?" We have a tree T with n vertices and m types of ice cream numerated from 1 to m . Each vertex i has a set of s i types of ice cream. Vertices which have the i -th ( 1 ≤ i ≤ m ) type of ice cream form a connected subgraph. We build a new graph G with m vertices. We put an edge between the v -th and the u -th ( 1 ≤ u , v ≤ m , u ≠ v ) vertices in G if and only if there exists a vertex in T that has both the v -th and the u -th types of ice cream in its set. The problem is to paint the vertices of G with minimum possible number of colors in a way that no adjacent vertices have the same color. Please note that we consider that empty set of vertices form a connected subgraph in this problem. As usual, Modsart don't like to abandon the previous problem, so Isart wants you to solve the new problem. The first line contains two integer n and m ( 1 ≤ n , m ≤ 3·10 5 ) — the number of vertices in T and the number of ice cream types. n lines follow, the i -th of these lines contain single integer s i ( 0 ≤ s i ≤ 3·10 5 ) and then s i distinct integers, each between 1 and m — the types of ice cream in the i -th vertex. The sum of s i doesn't exceed 5·10 5 . n - 1 lines follow. Each of these lines describes an edge of the tree with two integers u and v ( 1 ≤ u , v ≤ n ) — the indexes of connected by this edge vertices. Print single integer c in the first line — the minimum number of colors to paint the vertices in graph G . In the second line print m integers, the i -th of which should be the color of the i -th vertex. The colors should be between 1 and c . If there are some answers, print any of them. In the first example the first type of ice cream is present in the first vertex only, so we can color it in any color. The second and the third ice cream are both presented in the second vertex, so we should paint |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
26864484 |
FalseMirror |
C |
May 4, 2017, 6:15 p.m. |
OK |
D |
TESTS |
161 |
936 |
53964800 |
|
2200 |
|
26858643 |
imathi |
C |
May 4, 2017, 4:18 p.m. |
OK |
GNU C++ |
TESTS |
4 |
15 |
14438400 |
|
2200 |
|
26870291 |
xzyxzy |
C |
May 5, 2017, 1:50 a.m. |
OK |
GNU C++ |
TESTS |
161 |
140 |
36044800 |
|
2200 |
|
26870078 |
xzyxzy |
C |
May 5, 2017, 1:27 a.m. |
OK |
GNU C++ |
TESTS |
161 |
140 |
36044800 |
|
2200 |
|
40981534 |
ReaLNero1 |
C |
July 30, 2018, 6:02 p.m. |
OK |
GNU C++ |
TESTS |
161 |
155 |
36147200 |
|
2200 |
|
26895231 |
vjudge4 |
C |
May 6, 2017, 7:16 a.m. |
OK |
GNU C++ |
TESTS |
161 |
171 |
15155200 |
|
2200 |
|
26891453 |
AkaneSasu |
C |
May 6, 2017, 2:32 a.m. |
OK |
GNU C++ |
TESTS |
161 |
171 |
16588800 |
|
2200 |
|
30858976 |
Always |
C |
Sept. 30, 2017, 8:18 a.m. |
OK |
GNU C++ |
TESTS |
161 |
187 |
16896000 |
|
2200 |
|
26896270 |
vjudge3 |
C |
May 6, 2017, 8:18 a.m. |
OK |
GNU C++ |
TESTS |
161 |
187 |
23859200 |
|
2200 |
|
26857920 |
ACMLCZH |
C |
May 4, 2017, 4:13 p.m. |
OK |
GNU C++ |
TESTS |
161 |
187 |
24985600 |
|
2200 |
|
27443513 |
cbhcbh |
C |
May 30, 2017, 8:49 a.m. |
OK |
GNU C++ |
TESTS |
161 |
202 |
17817600 |
|
2200 |
|
51612535 |
Gloid |
C |
March 21, 2019, 11:07 a.m. |
OK |
GNU C++11 |
TESTS |
161 |
171 |
15667200 |
|
2200 |
|
54567655 |
lukelin |
C |
May 24, 2019, 5:23 p.m. |
OK |
GNU C++11 |
TESTS |
161 |
171 |
17817600 |
|
2200 |
|
54567576 |
vjudge1 |
C |
May 24, 2019, 5:20 p.m. |
OK |
GNU C++11 |
TESTS |
161 |
171 |
17817600 |
|
2200 |
|
45206661 |
sckalrter |
C |
Nov. 2, 2018, 1:06 p.m. |
OK |
GNU C++11 |
TESTS |
161 |
186 |
17817600 |
|
2200 |
|
26873106 |
will7101 |
C |
May 5, 2017, 5:09 a.m. |
OK |
GNU C++11 |
TESTS |
161 |
186 |
26112000 |
|
2200 |
|
27278420 |
rxdoi |
C |
May 22, 2017, 6:56 a.m. |
OK |
GNU C++11 |
TESTS |
161 |
187 |
16588800 |
|
2200 |
|
26873397 |
ditoly |
C |
May 5, 2017, 5:31 a.m. |
OK |
GNU C++11 |
TESTS |
161 |
187 |
16588800 |
|
2200 |
|
26880797 |
248926 |
C |
May 5, 2017, 12:50 p.m. |
OK |
GNU C++11 |
TESTS |
161 |
187 |
23859200 |
|
2200 |
|
26925300 |
LIN452 |
C |
May 7, 2017, 2:24 p.m. |
OK |
GNU C++11 |
TESTS |
161 |
202 |
23859200 |
|
2200 |
|
26880880 |
248926 |
C |
May 5, 2017, 12:54 p.m. |
OK |
GNU C++11 |
TESTS |
161 |
202 |
23859200 |
|
2200 |
|
26865886 |
Egor.Lifar |
C |
May 4, 2017, 7:03 p.m. |
OK |
GNU C++14 |
TESTS |
161 |
233 |
26316800 |
|
2200 |
|
27615189 |
AmberFrame |
C |
June 6, 2017, 1:41 p.m. |
OK |
GNU C++14 |
TESTS |
161 |
374 |
44851200 |
|
2200 |
|
48590922 |
antguz |
C |
Jan. 20, 2019, 2:07 a.m. |
OK |
GNU C++14 |
TESTS |
161 |
405 |
18636800 |
|
2200 |
|
27216079 |
rpSebastian |
C |
May 19, 2017, 2:06 p.m. |
OK |
GNU C++14 |
TESTS |
161 |
420 |
17920000 |
|
2200 |
|
46313551 |
3015218054 |
C |
Nov. 28, 2018, 2:37 p.m. |
OK |
GNU C++14 |
TESTS |
161 |
420 |
21811200 |
|
2200 |
|
45132410 |
heno239 |
C |
Oct. 31, 2018, 10:58 a.m. |
OK |
GNU C++14 |
TESTS |
161 |
420 |
28057600 |
|
2200 |
|
26876159 |
Jakube |
C |
May 5, 2017, 8:25 a.m. |
OK |
GNU C++14 |
TESTS |
161 |
421 |
18432000 |
|
2200 |
|
26864082 |
Vaness |
C |
May 4, 2017, 6:06 p.m. |
OK |
GNU C++14 |
TESTS |
161 |
421 |
18944000 |
|
2200 |
|
26884600 |
zhymaoiing |
C |
May 5, 2017, 4 p.m. |
OK |
GNU C++14 |
TESTS |
161 |
421 |
19046400 |
|
2200 |
|
65441835 |
_no0B |
C |
Nov. 20, 2019, 2:36 p.m. |
OK |
GNU C++14 |
TESTS |
161 |
421 |
19558400 |
|
2200 |
|
64772008 |
user202729_ |
C |
Nov. 13, 2019, 12:49 a.m. |
OK |
GNU C++17 |
TESTS |
161 |
405 |
18636800 |
|
2200 |
|
61843112 |
ST_C |
C |
Oct. 4, 2019, 10:24 a.m. |
OK |
GNU C++17 |
TESTS |
161 |
420 |
21811200 |
|
2200 |
|
45132375 |
vjudge3 |
C |
Oct. 31, 2018, 10:57 a.m. |
OK |
GNU C++17 |
TESTS |
161 |
451 |
28057600 |
|
2200 |
|
50680646 |
Mooncrater |
C |
March 2, 2019, 11:19 a.m. |
OK |
GNU C++17 |
TESTS |
161 |
452 |
18329600 |
|
2200 |
|
69097686 |
Phortox |
C |
Jan. 19, 2020, 12:43 p.m. |
OK |
GNU C++17 |
TESTS |
161 |
452 |
27955200 |
|
2200 |
|
52629717 |
vjudge2 |
C |
April 12, 2019, 6:19 a.m. |
OK |
GNU C++17 |
TESTS |
161 |
467 |
19865600 |
|
2200 |
|
49037227 |
linkRs |
C |
Jan. 27, 2019, 4:21 a.m. |
OK |
GNU C++17 |
TESTS |
161 |
467 |
23347200 |
|
2200 |
|
53876891 |
vjudge5 |
C |
May 8, 2019, 12:28 p.m. |
OK |
GNU C++17 |
TESTS |
161 |
467 |
24678400 |
|
2200 |
|
64504019 |
kska |
C |
Nov. 8, 2019, 5:58 a.m. |
OK |
GNU C++17 |
TESTS |
161 |
483 |
19353600 |
|
2200 |
|
64484272 |
devid |
C |
Nov. 7, 2019, 5:07 p.m. |
OK |
GNU C++17 |
TESTS |
161 |
483 |
32153600 |
|
2200 |
|
26860895 |
Martynas |
C |
May 4, 2017, 4:35 p.m. |
OK |
Go |
TESTS |
161 |
405 |
47104000 |
|
2200 |
|
26859866 |
uwi |
C |
May 4, 2017, 4:27 p.m. |
OK |
Java 8 |
TESTS |
161 |
436 |
19046400 |
|
2200 |
|
26873832 |
hama-du |
C |
May 5, 2017, 5:59 a.m. |
OK |
Java 8 |
TESTS |
161 |
436 |
37068800 |
|
2200 |
|
42275400 |
Taran_1407 |
C |
Aug. 30, 2018, 11:06 a.m. |
OK |
Java 8 |
TESTS |
161 |
686 |
45568000 |
|
2200 |
|
26866737 |
abhi1agarwal |
C |
May 4, 2017, 7:46 p.m. |
OK |
Java 8 |
TESTS |
161 |
842 |
82329600 |
|
2200 |
|
26853626 |
Slamur |
C |
May 4, 2017, 3:44 p.m. |
OK |
Java 8 |
TESTS |
161 |
872 |
87449600 |
|
2200 |
|
26853226 |
Lewin |
C |
May 4, 2017, 3:41 p.m. |
OK |
Java 8 |
TESTS |
161 |
873 |
108236800 |
|
2200 |
|
27110576 |
ChrisWu |
C |
May 14, 2017, 5:30 p.m. |
OK |
Java 8 |
TESTS |
161 |
888 |
82534400 |
|
2200 |
|
26876449 |
meijun |
C |
May 5, 2017, 8:44 a.m. |
OK |
Java 8 |
TESTS |
161 |
904 |
66764800 |
|
2200 |
|
26877510 |
fetetriste |
C |
May 5, 2017, 9:48 a.m. |
OK |
Java 8 |
TESTS |
161 |
951 |
77824000 |
|
2200 |
|
65925412 |
yaoct |
C |
Nov. 28, 2019, 6:03 p.m. |
OK |
Java 8 |
TESTS |
161 |
951 |
106393600 |
|
2200 |
|
26873597 |
dened |
C |
May 5, 2017, 5:45 a.m. |
OK |
Kotlin |
TESTS |
161 |
982 |
84275200 |
|
2200 |
|
26875948 |
camypaper |
C |
May 5, 2017, 8:15 a.m. |
OK |
MS C# |
TESTS |
161 |
452 |
48332800 |
|
2200 |
|
26863551 |
AnatolyTolstobrov |
C |
May 4, 2017, 5:55 p.m. |
OK |
MS C# |
TESTS |
161 |
467 |
54681600 |
|
2200 |
|
27181365 |
Aimerrhythm |
C |
May 17, 2017, 2:09 p.m. |
OK |
MS C++ |
TESTS |
161 |
312 |
68300800 |
|
2200 |
|
27192011 |
Aimerrhythm |
C |
May 18, 2017, 7:31 a.m. |
OK |
MS C++ |
TESTS |
161 |
327 |
68300800 |
|
2200 |
|
26902818 |
NVAL |
C |
May 6, 2017, 1:55 p.m. |
OK |
MS C++ |
TESTS |
161 |
467 |
28364800 |
|
2200 |
|
26860741 |
Filyan |
C |
May 4, 2017, 4:34 p.m. |
OK |
MS C++ |
TESTS |
161 |
577 |
35532800 |
|
2200 |
|
26851679 |
Perforator |
C |
May 4, 2017, 3:34 p.m. |
OK |
MS C++ |
TESTS |
161 |
670 |
81510400 |
|
2200 |
|
27196343 |
Aimerrhythm |
C |
May 18, 2017, 12:27 p.m. |
OK |
MS C++ |
TESTS |
161 |
1154 |
21811200 |
|
2200 |
|
27214430 |
Aimerrhythm |
C |
May 19, 2017, 12:37 p.m. |
OK |
MS C++ |
TESTS |
161 |
1263 |
21094400 |
|
2200 |
|
26867431 |
Ancient_mage |
C |
May 4, 2017, 8:30 p.m. |
OK |
MS C++ |
TESTS |
161 |
1372 |
77824000 |
|
2200 |
remove filters
Back to search problems