138.寻找宝藏

2019-03-25  本文已影响0人  欢城深喟
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
struct TreeNode{
    vector<int> 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;
} 
上一篇下一篇

猜你喜欢

热点阅读