__baozii__'s blog

By __baozii__, 8 months ago, In English

Hello Codeforces!

We are glad to invite you to participate in Codeforces Round 1042 (Div. 3), which will start on Aug/10/2025 17:35 (Moscow time). You will be given 2 hours and 15 minutes to solve 8 problems.

The problems are authored and prepared by -firefly-, efishel, Tobo, and __baozii__.

The round will be hosted by the rules of educational rounds (extended ICPC). Thus, all solutions will be judged on preliminary tests during the round, and after the round, there will be a 12-hour phase of open hacks. After the open hack phase, all accepted solutions will be rejudged on successful hacks. Also, note that there is no score distribution — rank will be determined by number of problems solved, followed by penalty; wrong submissions will incur the usual penalty of 10 minutes, following the rules of educational rounds.

As a reminder, only trusted participants of the third division will be included in the official standings table. This is a compulsory measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:

  • take part in (and solve at least one problem in) at least five rated rounds;
  • and not have had a rating of 1900 or higher at any moment in time.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you (unless you register unrated).

Also, note the rule restricting the use of AI. If you are caught breaking this rule, you will be thrown into -firefly-'s basement. For your own well-being, I suggest adhering to the rules.

We would like to thank the following people for helping make this round possible!

Good luck!

UPD: Editorial

  • Vote: I like it
  • +358
  • Vote: I do not like it

»
8 months ago, hide # |
 
Vote: I like it +34 Vote: I do not like it

1 blog upvote = 1 day closer to -firefly-'s cosplay pic

»
8 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

As a tester, I wonder what's in -firefly-'s basement?

»
8 months ago, hide # |
 
Vote: I like it +46 Vote: I do not like it

As an author, I vehemently condemn the egregious act of seizing my contribution.

»
8 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

As tester, I recommend that everyone participate in this amazing round!

»
8 months ago, hide # |
 
Vote: I like it +19 Vote: I do not like it

As a tester,I highly recommend the anime 'Clannad'.

»
8 months ago, hide # |
Rev. 3  
Vote: I like it +1 Vote: I do not like it

“Am I late? Am I ready to explode!”

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

I LOVE U baozii

»
8 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

As a tester, I can't wait for -firefly-'s cosplay.

»
8 months ago, hide # |
 
Vote: I like it +53 Vote: I do not like it

As a tester, I hope you all enjoy these problems!

»
8 months ago, hide # |
 
Vote: I like it -9 Vote: I do not like it

I think cry's basement has become full of cheaters, so now -firefly-'s basement will be used from now

»
8 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

i love you

»
8 months ago, hide # |
Rev. 2  
Vote: I like it +53 Vote: I do not like it

As a tester who have cooperated in __baozii__'s Baozii Cup, participated in -firefly-'s Soy Cup, and witnessed Tobo's NowCoder Summer Multi-School Training Camp 2025, I admire their creative thoughts, and hope any participant would enjoy those delicate problems!

PS: A simple drawing of Tobo

Click
»
8 months ago, hide # |
 
Vote: I like it +20 Vote: I do not like it

baozii lihai

»
8 months ago, hide # |
Rev. 2  
Vote: I like it +13 Vote: I do not like it

As a tester, I think I am the best green tester.

»
8 months ago, hide # |
 
Vote: I like it +19 Vote: I do not like it

as a tester i was late to the round announcement and will now receive no contribution being 16 comments down under the blog

the problems were good though i recommend participating even if youre out of competition

»
8 months ago, hide # |
 
Vote: I like it +10 Vote: I do not like it

As a tester, I was 6 hours too late to comment on the blog. However, thanks to myself procrastinating the comment, I am now able to orz __baozii__'s unbelievable performance in Atto Round 1 (Codeforces Round 1041, Div. 1 + Div. 2).

Hereby I commence the __baozii__ orz chain. __baozii__ orz

»
8 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

As a tester, this is the first time I'm hearing that I tested.

»
8 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

As an expert, this will be my first unrated d3

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Excited I guess?

»
8 months ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

As you all know,I'm cheyun's fan

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

memset(f, 0x3F, sizeof(f));

»
8 months ago, hide # |
 
Vote: I like it +30 Vote: I do not like it

This is Tobo.

^(* ̄(oo) ̄)^

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

I LOVE U __baozii__

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

-firefly-, Tobo, __baozii__, efishel, cry AND Proof_by_QED. I HAVE to participate. Also, do cry and -firefly- share a basement?

»
8 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

what is firefly. basement

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

I will hit green in this one!

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I wonder what's this "nutella testing". Sounds chocolaty though!

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

why did you not thank no one for grey testing??

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Waiting for comeback,,,,,,

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Waiting for comeback,,,,,,

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a "tester", I did not know of the existence of this contest LOL

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope I'll do good in this one

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why no div4 for a long time?

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    If I had to guess, it would likely be that div3s appeal to a wider audience while still providing good problems for beginners in contrast to div4s which has a really small rating range. Either that or there aren't a ton of contest submissions for div4s

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

...-----..--.--

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

500262984

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

cry's basement is filled up, new cheaters will be sent to -firefly-'s basement.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I declare here ,I definitely try at least 5 question this time . See you all after contest . Best of Luck!

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can i get a positive delta after a massive downfall...

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hey guys! I am new here so can I know if this div 3 will be easier than div 1+2 which was on Thursday (IST). I didn't got any questions in that round but well I was this close in solving the B question. I will appreciate any advice regarding joining what contests and how to practice on cf because I do well enough on leetcode.

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    This will almost certainly be easier than the div1+2, div3 has easier questions in general compared to the higher division rounds.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I will AC at least 4 questions, otherwise I will pull for E1 Firefly in HSR.

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Please pull at least E2

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    uhhh... Actually, I only got 3 Accepted NOW, so I'm going to pull Firefly. (Haha! E2 Firefly here I come!)

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      NOOOO BRO!!! I lost the final 50/50 to Fu Xuan and ran out of Stellar Jade (and my pocket money too)... Now my Firefly's stuck at E1. I swear I'll pull for that E2 on her rerun!

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by __baozii__ (previous revision, new revision, compare).

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

this will be a great round

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Ali_Adabi be like: I'm out of competition.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

shouldn't there be more cyan, green, and gray testers for a div 3?

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

hi all

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

where's a grey tester

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i have been in a basement and never want to be there again. (please dont put me in any basement thank you)

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

When preparing a contest , why do coordinators usually invite testers with different rating ranges ? How does this help ensure the contest quality and balance?

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    There is some good approach, it's called different view. It's like every raiting can evaluate it by itself, and tell his vision of this contest (during the testing ofc). So it can be helpful to understand the contest not only by one vision, but by different vision of ppl. So that's why it good) I hope u understood:)

»
8 months ago, hide # |
 
Vote: I like it -10 Vote: I do not like it

I’m participating in today’s contest. Hope I enjoy the problems as much as the testers did while testing them!

»
8 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

I hope I comeback to specialist with this one, and make a div 4 with errorgorn or cry or satyam343

»
8 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Hope from this contest i will back in form .

»
8 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

I see it is written,We would like to thank the following people for helping make this round possible! ... ... MikeMirzayanov for the incredible Codeforces and Polygon platforms. What is Polygon?

»
8 months ago, hide # |
Rev. 2  
Vote: I like it +1 Vote: I do not like it

Codeforces and Polygon may be unavailable from August 11, 15:30 (UTC) to August 12, 01:00 (UTC) due to technical maintenance. is anyone else getting this popup? will the contest happen as usual?

Edit: ok so today is 10th of august my bad

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I will hit Green today no matter what : )

»
8 months ago, hide # |
Rev. 2  
Vote: I like it +1 Vote: I do not like it

How could I be a tester

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Well. I tried CF first time in a while and it is really disappointing.

I have solved the first task of the contest, it works fine on my computer at least on the first test. But the system says the answer is wrong and the code execution on site hangs forever, so I can't even try to debug it. I use Go 1.22 compiler.

I had some passion to do algo but this platform has found a quick way to kill it =|

»
8 months ago, hide # |
 
Vote: I like it +22 Vote: I do not like it

I LOVE Problem H

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a purple tester I was a blue tester when I tested but the quality of this round made me a purple.

»
8 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

can GCD convolution + binary search + random pass H?

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    randomization is not intended for H. I hope those solutions can be hacked lol

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

for H, I'm constructing a bipartite graph between prime factors and a[i]. now (i, j) are coprime iff minimum distance in the graph between i and j is greater than 4 and I couldn't get this part done. any hints/help?

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem $$$B$$$ and $$$C$$$ are pure guessforces.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How to solve F?

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    hint: for path to (i, j) be good either all 1 to ai && 1 to bi be 1 or 0.

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      Thanks for the hint, I solved the problem

      Do you have any proof for this hint?

      • »
        »
        »
        »
        8 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        i don't know how to explain it... think of it like this.. each row will either be Array a or flip of Array a, (flip is just where there are 0's replace it with 1's and wise versa)

        now what we are doing is placing each row from top to bottom, now notice, whenever we have a flip, we can't go further down, (make a picture to fully understand what i am saying), there we can't have any flip, therefore Array b is gotta be all 0s or all 1s.

        now if we dont have any flips, and any element of Array a is 1, then the whole column becomes 1 therefore we can't go to right. thus all a's and b's should be same.

»
8 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

WOW FOR ME THIS WAS BEST CONTEST AS A PUPIL HOPING FOR + Δ

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I could only get A and C. best thing about having 600 elo is it doesn't go down lmao

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

F was a very nice problem but it is so hard to code.

Spoiler
»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

one of the best rounds in a couple months(at least among those i participated in)

Sadly, i couldn't solve FH(though i feel like i could) someone that solved H, can you explain the solution?

»
8 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

E easier than D

»
8 months ago, hide # |
 
Vote: I like it -7 Vote: I do not like it

i might be wrong but i found G easier than F, though implementation for G might be a little hard.

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Problem like D,E,F always make me wonder how authors think about the problems ? all problems were amazing Orz every authors

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i took one year break from CP and it hit me hard, I can’t even crack problem C now ,

idea behind C plzzzz?

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

nice contest

i enjoyed the tasks

(oh and problem A had a good name totally not biased)

»
8 months ago, hide # |
 
Vote: I like it +15 Vote: I do not like it
»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

liked the variety of this one, thanks for hosting!!

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

E was diabolical, I spent 20 minutes thinking 'there's no way it's just a for loop'

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Problem E was deceptively simple for its ranking. Took too long over sunk cost fallacy for D, when solving E would have been quicker.

»
8 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

D>>E.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

How the hell 7k peoples solve C ? when i was solving the question C suddenly notifications appears and changes the question so if it was wrong before then how 7k solve that ?

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is it just me or there is a curse of question number b? Never have I ever in my entire life got b correct on first try.

»
8 months ago, hide # |
Rev. 2  
Vote: I like it -8 Vote: I do not like it

Hacking phase is onn

»
8 months ago, hide # |
Rev. 2  
Vote: I like it -8 Vote: I do not like it

the contest was pretty good

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it +8 Vote: I do not like it

    1 step closer to deepseek you mean? Switching from C to H in 3 minutes and much more such cases are interesting))))

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Nowcoder has a problem that is same to 2131H nearly:牛客练习赛137F,2131H just is the special case when g=1 in Nowcoder Practice 137F。

I just submit my code after changing g=1 and get AC.

»
8 months ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

I'm feeling that the problem E is a bullshit. Does anyone agree with me?

»
8 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Can someone explain to me why my submission 333435436 for H is skipped?

I solved it completely by myself during contest, and the code is also pretty long so I don't think it would be similar to someone else's submission. I worked pretty hard to get this right after repeated wrong submissions. Is this some sort of bug?

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is it possible that we can get the testcase files, I want to check an approach but can't see the later testcases where it fails. please help!!! [user:tobo][user:efishel][user:-firefly-]

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    Unfortunately, you usually cannot get the actual test files since they are kept private by the organizers. But there’s a neat trick — inside your solution, you can detect when a certain test is running (for example, by a unique pattern in the input or by the test number), and then output the input of that specific test. This way, you can see exactly which test case causes your solution to fail.


    How it works in your code example:

    In the code, there are counters tests and cntt that track the current test number and how many times the solution was called. Inside the solve() function, after reading the input, you check:

    if (dd == 1 && tests == 3902) { cout << a << "\n"; cout << b << "\n"; }

    Here, tests == 3902 is the condition when the program outputs the input of test number 3902. The flag dd is set to 1 when n == 4 and cntt == 0 to activate the output mode for that test. If dd == 1, the function returns immediately without running the main algorithm, to avoid confusing output.

    So basically, you "catch" the needed test by its number or unique input features and print its data. This helps you see the exact test case that breaks your code without having access to the test files.


    This approach is very useful when you don’t have direct access to test files but can run your code on all tests.

    My code below as an example: https://mirror.codeforces.com/contest/2131/submission/333452022

»
8 months ago, hide # |
 
Vote: I like it +2 Vote: I do not like it

Problem H ate up almost all my time, and I ended up solving problems backwards, finishing as the last person with 8 problems solved.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Does anyone have a problem with problem C in python.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem E was easy but C ate the time for me :")

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello, I had registered for this contest and did not tick the "Unrated" option, but it is showing as unrated for me.
My handle: Amit_2700
Could you please check if my rating update was skipped?   Thank you.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I registered 1 minute after start, does that make the contest unrated for me

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
#include <bits/stdc++.h>
using namespace std;
#define	  pii			   std::pair<int,int>
#define	  vi				std::vector<int>
#define	  mp(a,b)		   make_pair(a,b)
#define	  pb(a)			 push_back(a)
#define	  each(it,s)		for(auto it = s.begin(); it != s.end(); ++it)
#define	  For(i, m, n)	  for(int i = m; i < (n); ++i)
#define	  ForD(i, m, n)	 for(int i = m; i >= n; i--)
#define	  fill(a,k)		 For(i,0,sizeof(a)/sizeof(a[0])) a[i] = k;
#define	  sortA(v)		  sort(v.begin(), v.end())
#define	  sortD(v)		  sort(v.begin(), v.end(), greater<auto>())
#define	  X				 first
#define	  Y				 second
#define	  Debug(x)		  cout<<"> "<<#x<<" : "<<x<<endl
#define	  DebugArr(a,n)	 For(i,0,n) cout<<i<<" : "<<a[i]<<endl
#define	  FAST			  ios_base::sync_with_stdio(false),cin.tie(0),cout.precision(17);
#define	  tests			 int T; cin >> T; while(T--) 
 
typedef long long ll;
const int mod = 1000000007, N = 300000;const ll inf = 1e18;
 
int main() {
    FAST;
    int t; cin >> t;
    while (t--) {
        int n, k; cin >> n >> k;
        vector<int> s(n), t(n);
        for (int i=0; i<n; i++) {
            cin >> s[i];
            s[i] = s[i]%k;
        }
        unordered_map<int, int> freq;
        for (int i=0; i<n; i++) {
            cin >> t[i];
            t[i] = t[i]%k;
            freq[t[i]]++;
        }
        bool ans = true;
        for (int i=0; i<n; i++) {
            if (freq[s[i]] > 0) {
                freq[s[i]]--;
            } else if (freq[abs(s[i]-k)] > 0) {
                freq[abs(s[i]-k)]--;
            } else {
                ans = false;    break;
            }
        }
        if (ans)    cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}

My solution for prob C, ACed during the contest... TLE in the system testing... shouldn't it work assuming unordered_map insertion, updation is O(1) amortized.

Can we somehow create test cases where the unordered_map performs poor? Can someone the reason behind TLE?

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    Never use unordered_map on codeforces, the worst time complexity of unordered_map is O(n), and they design a test case in such a way that it will lead to worst case time complexity.

    Use map<int,int> and I guess you won't get TLE.

  • »
    »
    8 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    In worst case unordered map take O(n), it's rare but sometimes happens due to hash collision. It is safer to use map instead of unordered map. Also hackers can deliberately design such test case to get an edge.i too got hacked here .

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

What does skipped verdict mean?

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hey, I have got a violation mail for the coincidence of my submission for the B problem in this contest Code forces round 1042 (DIV 3). My username is Aditya_0007 and my submission number is this "https://mirror.codeforces.com/contest/2131/submission/333302914". I think this solution is the basic one that anyone can think of and checking plagarism on such questions is too harsh, I request you to process this issue and remove that violation, Thank you.

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Was this contest not rated? My ratings have not changed

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

When will the contest be rated?

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello, I had registered for this contest and did not tick the "Unrated" option, but it is showing as unrated for me. My handle: Amit_2700 Could you please check if my rating update was skipped? Thank you.

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Why i have not rated in this round?

»
8 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

There are so many cheaters in this round, just open random 5-10 solutions of top official 500 people. You will easily see that the code is AI written, very long variable names, even some have detailed comments. I guess, codeforces needs to make cheating rule very strict. If someone is caught once, or twice, just ban the account. That's the only solution to prevent cheating else if this continues, then people who do not cheat will ultimately loose their confidence & either start cheating or leave CP.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone help me with problem D , I', getting WA while submiting this , what all I'm trying to is , get the node with max adj size, now mark node and the adj list as visited. Now , all the unvisited nodes I see would be with depth atleast greater than 1. Now, I'm doing a BFS and checking if adj list size is == 1 , increamenting the ans by 1.

here is the code:

#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin>>t;
 
    while(t--) {
        int n;
        cin>>n;
        int u, v;
        vector<vector<int> > G(n);
        for(int i=0; i<n-1; i++) {
            cin>>u>>v;
            u--; v--;
            G[u].push_back(v);
            G[v].push_back(u);
        }
        if(n<=3) {cout<<0<<endl; continue;}
        queue<int> q;
        int maxi = 0;
        int k=0, sz;
        for(int i=0; i<n; i++) {
            sz = G[i].size();
            if(maxi < sz) {
                maxi = sz;
                k = i;
            }
            
        }
     
        vector<bool> vis(n, false);
        vis[k] = true;
        for(int i=0; i<G[k].size(); i++) {
            q.push(G[k][i]);
            vis[G[k][i]] = true;
        }
        int p;
        int ans = 0;
        while(!q.empty()) {
            p = q.front();
            q.pop();
            for(int i = 0; i< G[p].size(); i++) {
                if(!vis[G[p][i]]) {
                    vis[G[p][i]] = true;
                    if(G[G[p][i]].size() == 1) {ans++; continue;}

                    q.push(G[p][i]);
                }
            }
        }
        cout<<ans<<endl;
    }
}

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

No rating change is it gone unrated :)

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

woah no rating update yet ??

»
8 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

when rating will be updated???

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

When We will see the rating changes??

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I really hope this contest doesn't go unrated

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Why this contest is showing unrated !

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello, I registered as a contestant for the contest, but it still seems unrated to me. I've seen the same thing happening to several contestants. Could any of the organizers please check if my rating update was omitted? I'd really appreciate it if you could check. Thank you.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hello please any organizers or any admin please confirm that why my ratings not got updated.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

maybe this contest went unrated due to the server maintenance? ಥ⁠‿⁠ಥ

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

was it unrated div 3 ?

no rating updated till now . almost 2 days passed .

i hope i would hit the green if it is rated .

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Why they edging us with the rating change.(⁠・ั⁠ω⁠・ั⁠)  ⁠ᗒ⁠ᗩ⁠ᗕ

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

hope it's rated :) want to reach expert this time.

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it

    And me!

    • »
      »
      »
      8 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      hey brother , would you please give me some topic list and way of practice for reaching expert ?

      thanks in advanced

      • »
        »
        »
        »
        8 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Hi! Well, if you look at last year and now, probably the main reasons were that I simply started solving more problems (not only on this site) and reading reviews (sounds trite, but it's true). Also, if I had been given problem D of this round a year ago, I would have spent the entire two hours thinking about paths and nothing else, from which we can conclude that it is very important to think deeper than what you were given in the conditions (in this problem, you could have thought about leaves and solved the problem!). It is also often useful to simplify a problem, reduce restrictions or whatever, for example, I came up with F of this round this way (you could have thought about it with N <= 1000 (after all, it is easier to think about a problem when you can solve it in n * n, and not n * logn or even n), this maneuver often helps me (but of course it does not always work, because there are problems where n * n is very easy to come up with, but nlong or n — not)). It also helps me a lot to draw and write on paper. Of course, the most important thing is to solve a lot of problems (at least with analysis (but first you need to think well yourself) (at least it helps me)). For me, this is the most important thing, although it may seem obvious =). I am writing through a translator, so it may not be clear, sorry.

      • »
        »
        »
        »
        8 months ago, hide # ^ |
        Rev. 2  
        Vote: I like it 0 Vote: I do not like it

        You don't need to know any difficult algorithms to become an expert, just think

  • »
    »
    8 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    :(

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Is this unrated ?

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

ratings updated!

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

No Rating update yet. Is it like this contest went unrated? Please anyone confirm.

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Me commenting as green :)

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone tell reason behind many person got skipped verdict in G.. I saw standings there are too many why is it soo... I have written whole code by myself can someone tell reason behind it..

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

s

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Hi, my handle is lawan11. I participated in this contest and was eligible for rating changes, but it shows 'Unrated for you'. Could you please check if this was a mistake?

»
8 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Hello baozii, I’m lawan11. I participated in Codeforces Round 1042 (Div. 3) with rating 900, registered correctly, and didn’t opt for unrated participation. However, the system shows “Unrated for you” and I’m the only one without a rating change. Could you kindly check if this was an error?

»
8 months ago, hide # |
Rev. 3  
Vote: I like it -10 Vote: I do not like it

Hello Codeforces team,

I want to clarify a situation regarding my submissions in the recent contest. I accidentally registered and submitted solutions from two different accounts I own. I understand that this caused the system to detect significant similarity between submissions, which looks like a rules violation.

I want to emphasize that there was no intention of cheating. The duplicate submissions were unintentional and occurred because I was experimenting with both accounts. I sincerely apologize for this mistake and assure you it will not happen again.

Thank you for your understanding.

Best regards

»
8 months ago, hide # |
Rev. 6  
Vote: I like it -10 Vote: I do not like it

Hello Codeforces team, I want to clarify a situation regarding my submissions in the recent contest. I submit one solution from my friends because I don't know the rules of system because it's my first trying on codeforces i think I registered Unrated that's ok for system i apologize for this wrong thing i did and my friend he didn't know that i submit his solution until the contests over. I understand that this caused the system to detect significant similarity between submissions, which looks like a rules violation. I want to emphasize that there was no intention of cheating. The duplicate submissions were unintentional and occurred because I was experimenting with both accounts. I sincerely apologize for this mistake and assure you it will not happen again.

Thank you for your understanding. I apologize to my friend because his solution is skeeped i hope codeforces will understand the wrong i did and return the solution accepted and please don't pan both and I am really sorry for what happenend Best regards

»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Dear Codeforces team, for the contest 1042(div 3) I got flagged for matching solutions to D and E with a single person https://mirror.codeforces.com/profile/n377a. I'd like to clarify that the other account is me with a different gmail.. I am sorry for this major overlook on my side... I just got excited with the possibility of me becoming cyan coder when I was able to solve the first 4 problems, hence the quick and same submissions on both profiles.. I apologize for this mistake and will make sure it never happens... P.S: Please just dont ban my main account.