138.寻找宝藏

#include
#include
using namespace std;
struct TreeNode{
    vector son;
    int father;
};
int main(){
    
    int N,M,L;
    scanf("%d %d %d",&N,&M,&L);
    TreeNode node[1010];
    
    for(int i=0;i<1010;i++){
        
        node[i].son.clear();
        node[i].father = -1;
    }
    
    while(M--){
        
        int a, b; //a->b
        scanf("%d %d", &a, &b);
        
        node[a].son.push_back(b);
        node[b].father = a;
    }
    
    double ans = 1;
    while(node[L].father != -1){
         
        L = node[L].father; 
        ans *= 1.0 / node[L].son.size();
    }
    
    printf("%.6lf\n", ans);
    
    return 0;
} 

你可能感兴趣的:(138.寻找宝藏)