Codeforces Round 1024 (Div. 1)

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.

ContestId
Name
Phase
Frozen
Duration (Seconds)
Relative Time
Start Time
2101 Codeforces Round 1024 (Div. 1) FINISHED False 9000 29431523 May 11, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 153 ) F Shoo Shatters the Sunshine PROGRAMMING combinatorics dp trees

You are given a tree with (n) vertices, where each vertex can be colored red, blue, or white. The coolness of a coloring is defined as the maximum distance(^{\text{∗}}) between a red and a blue vertex. Formally, if we denote the color of the (i)-th vertex as (c_i), the coolness of a coloring is (\max d(u, v)) over all pairs of vertices (1\le u, v\le n) where (c_u) is red and (c_v) is blue . If there are no red or no blue vertices, the coolness is zero. Your task is to calculate the sum of coolness over all (3^n) possible colorings of the tree, modulo (998\,244\,353). (^{\text{∗}})The distance between two vertices (a) and (b) in a tree is equal to the number of edges on the unique simple path between vertex (a) and vertex (b). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 50)). The description of the test cases follows. The first line of each test case contains a single integer (n) ((2\le n\le 3000)) — the number of vertices in the tree. Each of the next (n - 1) lines contains two integers (u) and (v) ((1\le u, v\le n)) — the endpoints of the edges of the tree. It is guaranteed that the given edges form a tree. It is guaranteed that the sum of (n) over all test cases does not exceed (3000). For each test case, output the sum of coolness over all (3^n) possible colorings of the tree, modulo (998\,244\,353). In the first test case, there are (12) colorings that have at least one blue and one red node. The following pictures show their coloring and their coolness: Therefore, the sum of coolness over all possible colorings is (6\cdot 2 + 6\cdot 1 = 18). In the second test case, the following are some examples of colorings with a coolness of (3):

Tutorials

142788

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
319286366 AliceMana F May 11, 2025, 4:51 p.m. OK C++17 (GCC 7-32) TESTS 64 2749 36249600
319280546 strapple F May 11, 2025, 4:32 p.m. OK C++20 (GCC 13-64) TESTS 64 734 307200
319302857 StarSilk F May 11, 2025, 7:33 p.m. OK C++20 (GCC 13-64) TESTS 64 905 108441600
319306331 AlefHeKaaf F May 11, 2025, 8:27 p.m. OK C++20 (GCC 13-64) TESTS 64 1562 73113600
319280605 Radewoosh F May 11, 2025, 4:33 p.m. OK C++20 (GCC 13-64) TESTS 64 2343 409600
319296545 Ormlis F May 11, 2025, 6:16 p.m. OK C++20 (GCC 13-64) TESTS 64 2859 102400
319281731 tourist F May 11, 2025, 4:36 p.m. OK C++20 (GCC 13-64) TESTS 64 3374 102400
319297072 turmax F May 11, 2025, 6:22 p.m. OK C++20 (GCC 13-64) TESTS 64 4546 144998400
319312734 N_z__ F May 11, 2025, 11:26 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 937 204800
319295385 ecnerwala F May 11, 2025, 6:05 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 1577 102400
319290279 tfg F May 11, 2025, 5:03 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 1702 102400
319307832 hos.lyric F May 11, 2025, 8:56 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 2640 72704000
319290581 244mhq F May 11, 2025, 5:04 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 3109 409600
319285038 ksun48 F May 11, 2025, 4:47 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 3609 102400
319307784 hos.lyric F May 11, 2025, 8:55 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 4358 72704000
319296938 maspy F May 11, 2025, 6:20 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 4718 409600
319294905 Benq F May 11, 2025, 6:01 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 6233 37068800
319295625 Swapil.Dey F May 11, 2025, 6:08 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 6280 37068800
319324815 muradbhai F May 12, 2025, 4:17 a.m. OK GNU C11 TESTS 64 3124 614400
319325395 muradbhai F May 12, 2025, 4:27 a.m. OK GNU C11 TESTS 64 3140 716800
319253827 rainboy F May 11, 2025, 3:35 p.m. OK GNU C11 TESTS 64 3281 716800
319317789 smilences F May 12, 2025, 2 a.m. OK PyPy 3-64 TESTS 64 4514 13414400
319318946 smilences F May 12, 2025, 2:28 a.m. OK PyPy 3-64 TESTS 64 5249 12697600
319319019 smilences F May 12, 2025, 2:29 a.m. OK PyPy 3-64 TESTS 64 6030 12697600
319318665 smilences F May 12, 2025, 2:21 a.m. OK PyPy 3-64 TESTS 64 6078 12595200
319318756 smilences F May 12, 2025, 2:23 a.m. OK PyPy 3-64 TESTS 64 6234 12697600

remove filters

Back to search problems