Codeforces Round 1069 (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
2174 Codeforces Round 1069 (Div. 1) FINISHED False 7200 11396723 Dec. 6, 2025, 8:15 a.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 289 ) D Secret Message PROGRAMMING data structures greedy trees

During long excursions in Turkey, you have seen many different mosaics, but you have never encountered one like this! The mosaic you see is a graph with (n) vertices and (m) edges of weight (w_i). You are so impressed by it that you decided to search for a secret message contained within it. You have considered many different options, and your current hypothesis is that the secret is the sum of the weights of a set of (n - 1) edges such that the sum is minimal and the edges do not form a tree. First, you want to find out this value, and what it means you plan to figure out on your way back home. Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. The first line of each test case contains two integers (n) and (m) ((2 \le n \le 2 \cdot 10^5), (n - 1 \le m \le 2 \cdot 10^5)) — the number of vertices and edges in the graph, respectively. The (i)-th of the following (m) lines contains three integers (u_i), (v_i), and (w_i) ((1 \le u_i \ne v_i \le n), (1 \le w_i \le 10^9)) — the description of the (i)-th edge. It is guaranteed that the graph does not contain self-loops or multiple edges. It is guaranteed that the sum of (n) across all test cases does not exceed (2 \cdot 10^5), and the sum of (m) across all test cases does not exceed (2 \cdot 10^5). For each test case, output a single integer — the minimum sum of weights of a set of (n - 1) edges that does not form a tree, if such a set exists. Otherwise, print (-1). In the first test case, you can choose the second, third and sixth edge, with a weight sum of (4 + 1 + 5 = 10). It can be verified that this set of edges do not form a tree. In the second test case, all possible subsets of (3) edges will form a tree. Hence, there is no solution.

Tutorials

Codeforces Round 1069 Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
352337097 btoandizi D Dec. 7, 2025, 4:53 a.m. OK C++17 (GCC 7-32) TESTS 64 343 38400000
352333651 SDSXC D Dec. 7, 2025, 3:58 a.m. OK C++17 (GCC 7-32) TESTS 64 343 42086400
352332666 Austin__Griffin D Dec. 7, 2025, 3:38 a.m. OK C++17 (GCC 7-32) TESTS 64 375 22528000
352272819 Deltaxab D Dec. 6, 2025, 2:41 p.m. OK C++17 (GCC 7-32) TESTS 64 453 212275200
352265559 wabca D Dec. 6, 2025, 1:51 p.m. OK C++17 (GCC 7-32) TESTS 64 578 38707200
352269792 oceeff D Dec. 6, 2025, 2:20 p.m. OK C++17 (GCC 7-32) TESTS 64 734 116428800
352324145 ibrahim_ashraf_Temos_Dp D Dec. 7, 2025, 12:25 a.m. OK C++17 (GCC 7-32) TESTS 64 843 108134400
352265727 08kevin2 D Dec. 6, 2025, 1:52 p.m. OK C++17 (GCC 7-32) TESTS 64 1218 72499200
352339290 Warma D Dec. 7, 2025, 5:25 a.m. OK C++17 (GCC 7-32) TESTS 64 1234 241152000
352315530 coldminded D Dec. 6, 2025, 8:56 p.m. OK C++20 (GCC 13-64) TESTS 64 390 103833600
352262814 Tobo D Dec. 6, 2025, 1:33 p.m. OK C++20 (GCC 13-64) TESTS 64 453 53350400
352279772 zjq123 D Dec. 6, 2025, 3:30 p.m. OK C++20 (GCC 13-64) TESTS 64 515 49664000
352337456 FantasyNumber D Dec. 7, 2025, 4:59 a.m. OK C++20 (GCC 13-64) TESTS 64 703 106905600
352320664 makrav D Dec. 6, 2025, 10:38 p.m. OK C++20 (GCC 13-64) TESTS 64 843 149299200
352297867 vedantkohad D Dec. 6, 2025, 5:55 p.m. OK C++20 (GCC 13-64) TESTS 64 1171 195584000
352342843 PREMM_DESAI D Dec. 7, 2025, 6:07 a.m. OK C++20 (GCC 13-64) TESTS 64 1203 195481600
352281241 BurnedChicken D Dec. 6, 2025, 3:42 p.m. OK C++20 (GCC 13-64) TESTS 64 1265 53964800
352309425 CarrotCarrot D Dec. 6, 2025, 7:32 p.m. OK C++20 (GCC 13-64) TESTS 64 1343 75161600
352283725 Mitsukasa_Ayase D Dec. 6, 2025, 4 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 296 54784000
352337269 btoandizi D Dec. 7, 2025, 4:56 a.m. OK C++23 (GCC 14-64, msys2) TESTS 64 343 52326400
352296486 _akasi D Dec. 6, 2025, 5:44 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 359 56627200
352280346 zfs732 D Dec. 6, 2025, 3:35 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 359 72294400
352284612 feniwcktree D Dec. 6, 2025, 4:07 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 484 52736000
352262480 woohyun_jng D Dec. 6, 2025, 1:30 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 484 57856000
352333435 masonpop D Dec. 7, 2025, 3:54 a.m. OK C++23 (GCC 14-64, msys2) TESTS 64 609 96768000
352263541 Dominater069 D Dec. 6, 2025, 1:37 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 640 122982400
352265842 satyam343 D Dec. 6, 2025, 1:52 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 640 149401600
352260461 zjdl D Dec. 6, 2025, 1:18 p.m. OK C++23 (GCC 14-64, msys2) TESTS 64 718 100147200

remove filters

Back to search problems