Codeforces Round 1059 (Div. 3)

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
2162 Codeforces Round 1059 (Div. 3) FINISHED False 8100 15693923 Oct. 17, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 2795 ) G Beautiful Tree PROGRAMMING constructive algorithms math trees

A tree is a connected graph without cycles. A tree is called beautiful if the sum of the products of the vertex labels for all its edges is a perfect square . More formally, let (E) be the set of edges in the tree. The tree is called beautiful if the value ()S = \sum_{\{u, v\} \in E} (u \cdot v)() is a perfect square. That is, there exists an integer (x) such that (S = x^2). You are given an integer (n). Your task is to construct a beautiful tree having (n) vertices or report that such a tree does not exist. The first line of input contains a single integer (t) ((1 \le t \le 10^4)) — the number of testcases. Each testcase contains a single integer (n) ((2 \le n \le 2\cdot10^5)). It is guaranteed that the sum of (n) over all the testcases does not exceed (2\cdot10^5). For each testcase, if there is no beautiful tree having (n) vertices, print (-1). Otherwise, print (n-1) lines denoting the edges of a beautiful tree having (n) vertices. Each line should contain two space-separated integers (u,v) ((1 \le u,v \le n)) representing an edge. The vertices can be printed in any order within an edge, and the edges can be printed in any order. Test case 1: No beautiful tree exists with (2) vertices. Hence, print (-1). Test case 2: Test case 3:

Tutorials

Codeforces Round 1059 (Div. 3) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
344510271 og.kostya G Oct. 18, 2025, 2:03 p.m. OK C# 10 TESTS 9 124 2662400
344492824 og.kostya G Oct. 18, 2025, 12:24 p.m. OK C# 13 TESTS 9 109 3072000
344535014 mateuszmj G Oct. 18, 2025, 4:32 p.m. OK C++17 (GCC 7-32) TESTS 9 62 0
344425499 sunlight_codeforce G Oct. 18, 2025, 3:41 a.m. OK C++17 (GCC 7-32) TESTS 9 62 0
344425386 sunlight_codeforce G Oct. 18, 2025, 3:39 a.m. OK C++17 (GCC 7-32) TESTS 9 62 0
344497771 ItzsleepyXD G Oct. 18, 2025, 12:52 p.m. OK C++17 (GCC 7-32) TESTS 9 62 102400
344425076 ItzsleepyXD G Oct. 18, 2025, 3:34 a.m. OK C++17 (GCC 7-32) TESTS 9 62 102400
344590391 vikpo G Oct. 19, 2025, 5:57 a.m. OK C++17 (GCC 7-32) TESTS 9 77 0
344581438 zihan_shen G Oct. 19, 2025, 3:54 a.m. OK C++17 (GCC 7-32) TESTS 9 77 0
344523282 aaa.abbbb G Oct. 18, 2025, 3:17 p.m. OK C++17 (GCC 7-32) TESTS 9 77 0
344512338 Derarinho G Oct. 18, 2025, 2:14 p.m. OK C++17 (GCC 7-32) TESTS 9 77 0
344504391 catandcode G Oct. 18, 2025, 1:31 p.m. OK C++17 (GCC 7-32) TESTS 9 77 0
344435224 _andyli G Oct. 18, 2025, 5:26 a.m. OK C++20 (GCC 13-64) TESTS 9 46 2150400
344423350 manojvarma G Oct. 18, 2025, 3:10 a.m. OK C++20 (GCC 13-64) TESTS 9 61 0
344507319 HVCYM G Oct. 18, 2025, 1:48 p.m. OK C++20 (GCC 13-64) TESTS 9 61 819200
344430247 Ermiooo158 G Oct. 18, 2025, 4:38 a.m. OK C++20 (GCC 13-64) TESTS 9 61 1638400
344574258 arthurxu17 G Oct. 19, 2025, 1:14 a.m. OK C++20 (GCC 13-64) TESTS 9 61 7270400
344579114 HossamIsmail BidoTeima a1abay G Oct. 19, 2025, 3:11 a.m. OK C++20 (GCC 13-64) TESTS 9 62 0
344574360 arthurxu17 G Oct. 19, 2025, 1:17 a.m. OK C++20 (GCC 13-64) TESTS 9 62 0
344562477 xorman G Oct. 18, 2025, 8:21 p.m. OK C++20 (GCC 13-64) TESTS 9 62 0
344560214 0917ba G Oct. 18, 2025, 7:54 p.m. OK C++20 (GCC 13-64) TESTS 9 62 0
344541320 harshagr0110 G Oct. 18, 2025, 5:13 p.m. OK C++20 (GCC 13-64) TESTS 9 62 0
344583974 singhnaad G Oct. 19, 2025, 4:38 a.m. OK C++23 (GCC 14-64, msys2) TESTS 9 46 102400
344569537 AnasMaged G Oct. 18, 2025, 10:25 p.m. OK C++23 (GCC 14-64, msys2) TESTS 9 61 0
344533144 Ruthvik2835 G Oct. 18, 2025, 4:20 p.m. OK C++23 (GCC 14-64, msys2) TESTS 9 61 0
344513720 Neo00 G Oct. 18, 2025, 2:22 p.m. OK C++23 (GCC 14-64, msys2) TESTS 9 61 0
344501425 THE_DARKHORSE G Oct. 18, 2025, 1:13 p.m. OK C++23 (GCC 14-64, msys2) TESTS 9 61 0
344435147 .Mortis G Oct. 18, 2025, 5:26 a.m. OK C++23 (GCC 14-64, msys2) TESTS 9 61 0
344582795 Bhavesh_77 G Oct. 19, 2025, 4:18 a.m. OK C++23 (GCC 14-64, msys2) TESTS 9 62 0
344582454 Maburb G Oct. 19, 2025, 4:12 a.m. OK C++23 (GCC 14-64, msys2) TESTS 9 62 0
344582353 Illya1221 G Oct. 19, 2025, 4:11 a.m. OK C++23 (GCC 14-64, msys2) TESTS 9 62 0
344571816 Ajay967 G Oct. 18, 2025, 11:34 p.m. OK C++23 (GCC 14-64, msys2) TESTS 9 62 0
344578944 cpp10 G Oct. 19, 2025, 3:07 a.m. OK Java 21 TESTS 9 281 1843200
344572514 kartik__sethi G Oct. 19, 2025, 12:04 a.m. OK Java 21 TESTS 9 312 819200
344578854 cpp10 G Oct. 19, 2025, 3:06 a.m. OK Java 21 TESTS 9 327 512000
344498980 vineetiwari G Oct. 18, 2025, 12:58 p.m. OK Java 21 TESTS 9 343 921600
344494632 utsav_deep G Oct. 18, 2025, 12:33 p.m. OK Java 21 TESTS 9 389 9625600
344428546 ChickenTamer G Oct. 18, 2025, 4:19 a.m. OK PyPy 3-64 TESTS 9 202 8704000
344433520 helltractor G Oct. 18, 2025, 5:12 a.m. OK PyPy 3-64 TESTS 9 233 11468800
344569238 ApprenticeOfCode G Oct. 18, 2025, 10:18 p.m. OK PyPy 3-64 TESTS 9 249 8704000
344418883 cy171 G Oct. 18, 2025, 1:57 a.m. OK PyPy 3-64 TESTS 9 249 9625600
344530138 0xM7md G Oct. 18, 2025, 4 p.m. OK PyPy 3-64 TESTS 9 249 9728000
344509265 the_seal G Oct. 18, 2025, 1:58 p.m. OK PyPy 3-64 TESTS 9 265 9728000
344422711 kaosar_the_Joyboy G Oct. 18, 2025, 3 a.m. OK PyPy 3-64 TESTS 9 265 9830400
344543672 Cenix820 G Oct. 18, 2025, 5:30 p.m. OK PyPy 3-64 TESTS 9 265 10649600
344433169 DeadMan69 G Oct. 18, 2025, 5:09 a.m. OK PyPy 3-64 TESTS 9 280 17817600
344579529 IamYessir G Oct. 19, 2025, 3:19 a.m. OK PyPy 3-64 TESTS 9 281 9625600
344497849 ehsansoltanm G Oct. 18, 2025, 12:52 p.m. OK Python 3 TESTS 9 171 36044800
344493322 FuYn666 G Oct. 18, 2025, 12:27 p.m. OK Python 3 TESTS 9 202 36556800
344426080 FuYn666 G Oct. 18, 2025, 3:49 a.m. OK Python 3 TESTS 9 218 36556800
344561790 MadBread G Oct. 18, 2025, 8:13 p.m. OK Python 3 TESTS 9 312 204800
344515786 gautamb1a2b G Oct. 18, 2025, 2:34 p.m. OK Python 3 TESTS 9 359 307200
344496260 a_0dnok1 G Oct. 18, 2025, 12:43 p.m. OK Python 3 TESTS 9 374 204800
344505817 KinaRight G Oct. 18, 2025, 1:40 p.m. OK Python 3 TESTS 9 531 18944000
344511939 mxq G Oct. 18, 2025, 2:12 p.m. OK Python 3 TESTS 9 608 25190400

remove filters

Back to search problems