思路借鉴了之前的图的层数,发现这个贼好用;关键在于输出浮点数的格式,这个要注意一下
#include#include #include #include #include #include using namespace std;using std::vector;using std::queue;const int maxn=100010;struct node{ double data; vector child; int layer=0;}Node[maxn];int n;double p,r;vector leaf;void BFS(int x){ int layer=0; queue q; q.push(x); while(!q.empty()){ layer++; int index; int length=q.size(); for(int i=0;i