Account
Draft saved on this device
▤ DescriptionOriginal CppValley problem
Core C++Easy

Track Move-Only Resource Ownership

Simulate ownership transfers of non-copyable C++ resources.

There are N named resource handles, indexed 1..N; initially none own a resource. CREATE i assigns a new resource to handle i. MOVE a b moves ownership FROM handle b TO handle a, leaving b empty; the previous resource of a is released. RESET i releases any resource owned by i. Print the number of handles that own a resource after processing all commands. Model valid move-only ownership rules.

Input format

First line: N Q. Next Q lines: CREATE i, MOVE a b, or RESET i.

Output format

Print the count of nonempty handles after the final command.

Examples

Example 1
Input
3 5
CREATE 1
CREATE 2
MOVE 3 1
RESET 2
CREATE 1
Expected output
2

Handles 1 and 3 own resources.

Constraints

  • 1 ≤ N ≤ 100000
  • 1 ≤ Q ≤ 100000
  • 1 ≤ a,b,i ≤ N
  • For MOVE a b, a ≠ b.

Related concepts

RAIIMove SemanticsOwnership

This early-access exercise uses standard input/output. More advanced concurrency challenges will use specialized class interfaces, instrumentation, and stress tests once the judging infrastructure is ready.

⌘ CodeC++17
GNU C++17 · main.cpp

Loading Monaco C++ editor…

Checking judge...

Checking whether the external C++ judge is available.

⌁ Test cases & resultsPublic samples: 1
Input
3 5
CREATE 1
CREATE 2
MOVE 3 1
RESET 2
CREATE 1
Expected output
2
Execution requires a secure external judge.