Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew πŸš€
Contest SolutionsPractice
Practice Sheets
MasterclassesLive πŸ‘¨πŸ»β€πŸ’»

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
Β© 2026coding75β€’crackDSAβ„’β€’Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021β€’Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/Codeforces/Educational Codeforces Round 165/A. Two Friends
Next
CodeforcesCodeforces
Newbie
Educational Codeforces Round 165

A. Two Friends

ArrayMath
Loading...
Solve on Codeforces

Problem Statement

Official algorithmic problem description and constraints.

Open on Codeforces

Monocarp wants to throw a party. He has π‘› friends, and he wants to have at least 2 of them at his party.

The π‘–-th friend's best friend is π‘π‘–. All π‘π‘– are distinct, and for every π‘–βˆˆ[1,𝑛], π‘π‘–≠𝑖.

Monocarp can send invitations to friends. The π‘–-th friend comes to the party if both the π‘–-th friend and the π‘π‘–-th friend receive an invitation (note that the π‘π‘–-th friend doesn't have to actually come to the party). Each invitation is sent to exactly one of the friends.

For example, if π‘=[3,1,2,5,4], and Monocarp sends invitations to the friends [1,2,4,5], then the friends [2,4,5] will come to the party. The friend 1 won't come since his best friend didn't receive an invitation; the friend 3 won't come since he didn't receive an invitation.

Calculate the minimum number of invitations Monocarp has to send so that at least 2 friends come to the party.

Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Educational Codeforces Round 165
Next Problem