The approach is direct: run Kosaraju or Tarjan to find all SCCs in the graph. The number of SCCs equals the minimum number of kingdoms. Why?
Each SCC is a maximal group of mutually reachable nodes, so you cannot combine two different SCCs into one kingdom. Assign each node the ID of its SCC (a number from to the number of SCCs). Print the total SCC count first, then print each node's SCC ID in order from node to node .