BUPT OJ 尋找寶藏

水題

#include<iostream>
#include<iomanip>
using namespace std;
class node
{public:
	int parent;
	int branches;
	node()
	{
		branches=0;
		parent=-1;
	}
};
const int MAXSIZE = 10000;
class tree
{public:
	node point[MAXSIZE];
	int num;
};
int main()
{

  int N,M,L;
     cin>>N>>M>>L;
  int fa,son;   
  	tree res;
  	res.num=N;
	 while(M--)
     {
     	cin>>fa>>son;
     	res.point[fa].branches++;
     	res.point[son].parent=fa;
     	
    }
    
    node temp=res.point[L];
    int total_branches=1;
	while(temp.parent!=-1)
    {
    	
    	total_branches*=res.point[temp.parent].branches;
    	temp=res.point[temp.parent];
    	
	}
	cout.setf(ios::fixed);
    cout<<setprecision(6)<<1.0/total_branches<<endl;

} 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章