Question link: Click the open link
Question:
There are n backpacks on the ground, numbered from 1-n
Line I in line N below: the first number indicates the number of backpacks in the backpack I.
In this way, a state of N backpacks is obtained.
Q: How many backpacks can be entered through a series of operations.
Each step:
Select a backpack A on the ground, put the backpack inside a on the ground, put the backpack inside a on the ground
Ideas:
We can express the nested relationship of a backpack in a figure.
Then we got a forest and connected all the packets on the ground with the ground as the root. Then we got a tree.
Therefore, each operation is equivalent to a root change operation.
Therefore, a total of N-1 methods can be used to move the root to other places. (Drawing simulation)
(This must be determined when one backpack is used)
#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <map>#include <set>#include <stack>#include <iostream>#include <algorithm>using namespace std;typedef long long ll;int main() {int n, x, y;while (~scanf("%d", &n)) {for (int i = 1; i <= n; ++i) {scanf("%d", &x);while (x -- > 0) {scanf("%d", &y);}}if (n == 1)puts("1");elseprintf("%d\n", n + 1);}return 0;}
Sgu 238 Uncle Vasya and bags for potatoes law + Construction