Under construction

Still being built. Things may change

Split the Attractions

Time limit2sMemory limit1024 MB

Summary
Partition the vertices of a connected graph into sets of sizes a, b, and c so that at least two of the sets are connected.
Level

Medium7 of 10

Topics
DFS, Tree, Graph, Greedy
Solved
No attempts yet

Problem

There are nn attractions in Baku, numbered from 00 to n−1n-1. There are also mm two-way roads, numbered from 00 to m−1m-1. Each road connects two different attractions. Any pair of attractions can be reached from each other through the roads.

Fatima plans to visit all of the attractions in three days. She wants to visit aa attractions on the first day, bb on the second day, and cc on the third day. She will partition the nn attractions into three sets AA, BB, and CC of sizes aa, bb, and cc. Each attraction belongs to exactly one set, so a+b+c=na + b + c = n.

A set SS of attractions is connected if any two attractions in SS can reach each other by roads without passing through an attraction outside SS. Find sets AA, BB, and CC so that at least two of the three sets are connected. A partition that meets this condition is valid.

Given aa, bb, and cc, find a valid partition, or determine that no valid partition exists. If several valid partitions exist, you may output any of them.

Constraints

  • 3≤n≤100 0003 \leq n \leq 100\,000
  • 2≤m≤200 0002 \leq m \leq 200\,000
  • 1≤a,b,c≤n1 \leq a, b, c \leq n
  • a+b+c=na+b+c = n
  • There is at most one road between each pair of attractions.
  • Any pair of attractions can be reached from each other through the roads.
  • 0≤p[i],q[i]≤n−10 \leq p[i], q[i] \leq n-1 and p[i]≠q[i]p[i] \neq q[i] for 0≤i≤m−10 \leq i \leq m - 1

Examples1

  1. Example 1

    Input
    3 2
    0 1
    1 2
    1 1 1
    
    Expected output
    YES
    2 1 3