Language: C++

#include<iostream>
#include<vector>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
#define MAX 100
#define INFTY (1<<21)

void dijkstra( int n, int G[MAX][MAX],  vector<int> p[MAX] ){
  int d[MAX];
  bool visited[MAX];

  rep(i, n) p[i].clear();

  rep(i, n){
    d[i] = INFTY;
    visited[i] = false;
  }

  d[0] = 0;

  int cnt = 0;
  while(1){
    int minv = INFTY;
    int u = -1;
    rep(i, n){
      if ( !visited[i] && minv > d[i] ) {
	u = i;
	minv = d[i];
      }
    }
    if ( u == -1 ) break;
    visited[u] = true;
    cnt++;

    rep(v, n){
      if ( !visited[v] && G[u][v] != INFTY ){
	int cost = d[u] + G[u][v];
	if ( cost == d[v] ){
	  p[v].push_back(u);
	} else if ( cost < d[v] ){
	  p[v].clear();
	  p[v].push_back(u);
	  d[v] = cost;
	}
      }
    }
  }

  assert( cnt == n );
}

void tsort( int n, int u, bool T[MAX][MAX], vector<int> &order, bool visited[MAX], vector<int> p[MAX] ){
  visited[u] = true;
  rep(v, n) if ( T[u][v] && !visited[v]) tsort(n, v, T, order, visited, p);

  if ( u == 0 || u == n-1 || p[u].size() > 0 ){
    order.push_back(u);
  }
}

void parse( int n, int u, vector<int> p[MAX], bool inpath[MAX]){
  inpath[u] = true;
  for ( int i = 0; i < p[u].size(); i++ ){
    int v = p[u][i];
       if ( !inpath[v] )parse(n, v, p, inpath);
       // parse(n, v, p, inpath);
  }
}

void makeTree(int n, bool T[MAX][MAX], vector<int> p[MAX], int q){
  bool inpath[MAX];
  rep(i, n) inpath[i] = false;
  parse(n, n-1, p, inpath);

  rep(i, n) rep(j, n) T[i][j] = false;
  rep(v, n){
    rep(i, p[v].size()){
      int u = p[v][i];
      if ( inpath[u] && inpath[v] ) T[u][v] = true;
    }
  }

  vector<int> order;
  bool visited[MAX]; 

  rep(i, n) visited[i] = false;
  order.clear();
  tsort(n, 0, T, order, visited, p);
  reverse(order.begin(), order.end());

  double forward[MAX], back[MAX];
  rep(i, n) forward[i] = back[i] = 0.0;

  //rep(i,n) cout << order[i] << " ";
  //cout << endl;

  assert( order[0] == 0 );
  assert( order[order.size()-1] == n-1 );
  forward[order[0]] = 1;
  for ( int i = 0; i < order.size(); i++ ){
    int u = order[i];
    rep(v, n){
      if ( T[u][v] ) forward[v] += forward[u];
    }
  }
  for ( int i = 0; i < n; i++ ){
    if ( 0 == i ) continue;
    forward[i] /= forward[n-1];
  }
  
  rep(i, n) visited[i] = false;
  order.clear();
  // Tt
  bool tmp[MAX][MAX];
  /*
 rep(i, n){
    rep(j, n) cout << T[i][j] << " ";
    cout << endl;
    }*/
  rep(i, n) rep(j, n) tmp[j][i] = T[i][j];
  rep(i, n) rep(j, n) T[i][j] = tmp[i][j];

  /*
  rep(i, n){
    rep(j, n) cout << T[i][j] << " ";
    cout << endl;
  }
    cout << endl;
  */


  tsort(n, n-1, T, order, visited, p);
  reverse(order.begin(), order.end());

  //  rep(i, n) cout << order[i] << " ";
  //  cout << endl;

  assert( order[0] == n-1 );
  assert( order[order.size()-1] == 0 );
  back[order[0]] = 1.0;
  for ( int i = 0; i < order.size(); i++ ){
    int u = order[i];
    rep(v, n){
      if ( T[u][v] ) back[v] += back[u];
    }
  }

  double base = 1.0; // back[0];
  for ( int i = 0; i < n; i++ ){
    if ( i == n-1 ) continue;
    // back[i] = back[i]/back[0];
    back[i] = back[i]/base;

  }


  /*
  rep(i, n){
    //printf("%.4lf %.4lf %.4lf\n", forward[i], back[i], forward[i]*back[i]);
    printf("%.8lf\n", forward[i]*back[i]);
  }
  cout << endl;
  */

  int req;

  rep(i, q){
    cin >> req;
    assert( 0 < req && req < n-1 );
    printf("%.12lf\n", forward[req]*back[req]);
    
	//printf("%.12lf * %.2lf = %.12lf\n", forward[req], back[req], forward[req]*back[req]);
  }

  
  cout << endl;

}


main(){
  int n, m, q, G[MAX][MAX], s, t, c;
  bool T[MAX][MAX];
  vector<int> p[MAX];
  while(1){
    cin >> n >> m >> q;
    if ( n == 0 && m == 0 && q == 0) break;

    assert( 3 <= n && n <= 100 );
    assert( m <= 10000 );

    rep(i, n) rep(j, n) G[i][j] = INFTY;
    rep(i, m){
      cin >> s >> t >> c;
      G[s][t] = G[t][s] = c;
    }
    dijkstra(n, G, p);
    makeTree(n, T, p, q);
  }
}

Compiler output:
a.cc: In function 'void dijkstra(int, int (*)[100], std::vector<int>*)':
a.cc:49:3: error: 'assert' was not declared in this scope
   49 |   assert( cnt == n );
      |   ^~~~~~
a.cc:3:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    2 | #include<vector>
  +++ |+#include <cassert>
    3 | using namespace std;
a.cc: In function 'void makeTree(int, bool (*)[100], std::vector<int>*, int)':
a.cc:89:3: error: 'reverse' was not declared in this scope
   89 |   reverse(order.begin(), order.end());
      |   ^~~~~~~
a.cc:97:3: error: 'assert' was not declared in this scope
   97 |   assert( order[0] == 0 );
      |   ^~~~~~
a.cc:97:3: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
a.cc: At global scope:
a.cc:181:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  181 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:189:5: error: 'assert' was not declared in this scope
  189 |     assert( 3 <= n && n <= 100 );
      |     ^~~~~~
a.cc:189:5: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'