Problem:
Problem H:
Winter Bells
The best night ever in the world has come! It's 8 p.m. of December 24th, yes, the night of Cristmas Eve. Santa Clause comes to a silent city with ringing bells. Overtaking north wind, from a sleigh a reindeer pulls she shoot presents to soxes hanged near windows for children.
The sleigh she is on departs from a big christmas tree on the fringe of the city. Miracle power that the christmas tree spread over the sky like a web and form a paths that the sleigh can go on. Since the paths with thicker miracle power is easier to go, these paths can be expressed as undirected weighted graph.
Derivering the present is very strict about time. When it begins dawning the miracle power rapidly weakens and Santa Clause can not continue derivering any more. Her pride as a Santa Clause never excuses such a thing, so she have to finish derivering before dawning.
The sleigh a reindeer pulls departs from christmas tree (which corresponds to 0th node), and go across the city to the opposite fringe (
n
-1 th node) along the shortest path. Santa Clause create presents from the miracle power and shoot them from the sleigh the reindeer pulls at his full power. If there are two or more shortest paths, the reindeer selects one of all shortest paths with equal probability and go along it.
By the way, in this city there are
p
children that wish to see Santa Clause and are looking up the starlit sky from their home. Above the
i
-th child's home there is a cross point of the miracle power that corresponds to
c
[
i
]-th node of the graph. The child can see Santa Clause if (and only if) Santa Clause go through the node.
Please find the probability that each child can see Santa Clause.
Input
Input consists of several datasets.
The first line of each dataset contains three integers
n
,
m
,
p
, which means the number of nodes and edges of the graph, and the number of the children. Each node are numbered 0 to
n
-1.
Following
m
lines contains information about edges. Each line has three integers. The first two integers means nodes on two endpoints of the edge. The third one is weight of the edge.
Next
p
lines represent
c
[
i
] respectively.
Input terminates when
n
=
m
=
p
= 0.
Output
For each dataset, output
p
decimal values in same order as input. Write a blank line after that.
You may output any number of digit and may contain an error less than 1.0e-6.
Constraints
3 ≤
n
≤ 100
There are no parallel edges and a edge whose end points are identical.
0 < weight of the edge < 10000
Sample Input
3 2 1
0 1 2
1 2 3
1
4 5 2
0 1 1
0 2 1
1 2 1
1 3 1
2 3 1
1
2
0 0 0
Output for the Sample Input
1.00000000

0.50000000
0.50000000

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;

void fastIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}


const int oo = 1e9;
vector<vector<pair<long long, long long>>> adj;
int n, m;

int getShortestPath(int src, int target){
    vector<int> dist(n, oo);
    dist[src] = 0;

    priority_queue<pair<long long, long long>> pq;
    pq.push({0, src});

    while (!pq.empty())
    {
        long long u = pq.top().second;
        long long cost = -pq.top().first;
        pq.pop();

        if(dist[u] < cost) continue;

        for(auto [v, w] : adj[u])
        {
            if(dist[v] > dist[u] + w)
            {
                dist[v] = dist[u] + w;
                pq.push({-dist[v], v});
            }
        }
    }
    return dist[target];
}

long double getPathsCnt(long long src, long long target)
{
    vector<int> dist(n, oo);
    vector<long double > cnt(n, 0);
    dist[src] = 0; cnt[src] = 1;

    priority_queue<pair<long long, long long>> pq;
    pq.push({0, src});

    while (!pq.empty())
    {
        long long u = pq.top().second;
        long long cost = -pq.top().first;
        pq.pop();

        if(dist[u] < cost) continue;
        for(auto [v, w] : adj[u])
        {
            if(dist[v] > dist[u] + w)
            {
                cnt[v] = cnt[u];
                dist[v] = dist[u] + w;
                pq.push({-dist[v], v});
            }
            else if(dist[v] == dist[u] + w){
                cnt[v] += cnt[u];
            }
        }
    }
    return cnt[target];
}

signed main() {
    fastIO();

    int p;
    while(cin >> n >> m >> p){
        if(!n) break;

        adj.assign(n, {});
        for (int i = 0; i < m; ++i) {
            int u, v, w; cin >> u >> v >> w;
            adj[u].push_back({v, w});
            adj[v].push_back({u, w});
        }

        vector<int> childs(p);
        for (int i = 0; i < p; ++i) {
            cin >> childs[i];
        }

        long double  total = getPathsCnt(0, n - 1);
        for (int i = 0; i < childs.size(); ++i) {
            if(getShortestPath(0, childs[i]) + getShortestPath(childs[i], n - 1) == getShortestPath(0, n - 1)){
                cout << fixed << setprecision(7) << 1.0 * getPathsCnt(0, childs[i]) * getPathsCnt(childs[i], n - 1) / total << "\n";
            }
            else{
                cout << "0\n";
            }
        }
        cout << "\n";
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3656
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> edge;
typedef vector<edge> ve;
typedef vector<ve> graph;

int main(){
  int n,m,p;
  while(cin >> n >> m >> p, n){
    graph g(n);
    for(int i=0;i<m;i++){
      int a,b,c;
      cin >> a >> b >> c;
      g[a].push_back(edge(c,b));
      g[b].push_back(edge(c,a));
    }

    vi c(p);
    for(int i=0;i<p;i++)cin >> c[i];

    vi d(n,1e9), order;
    d[0] = 0;
    priority_queue< edge,vector<edge>,greater<edge> > pq;
    pq.push(edge(0,0));

    while(pq.size()){
      int dis = pq.top().first, v = pq.top().second; pq.pop();
      if(d[v] < dis)continue;
      order.push_back(v);

      for(edge e : g[v]){
	int nxtd = dis + e.first, u = e.second;
	if(d[u] > nxtd){
	  d[u] = nxtd;
	  pq.push(edge(nxtd,u));
	}
      }
    }

    vector<double> cnt(n,0);
    cnt[n-1] = 1;
    for(int i=order.size()-1;i>=0;i--){
      int v = order[i];
      for(edge e : g[v]){
	int dis = e.first, u = e.second;
	if(d[v] == d[u] + dis)cnt[u] += cnt[v];
      }
    }

    vector<double> prob(n,0);
    prob[0] = 1;
    for(int i=0;i<n;i++){
      int v = order[i];

      for(edge e : g[v]){
	int nxtd = d[v] + e.first, u = e.second;
	if(d[u] == nxtd){
	  prob[u] += prob[v] * cnt[u] / cnt[v];
	}
      }
    }

    for(int i=0;i<p;i++){
      cout << fixed << setprecision(9) << prob[c[i]] << endl;
    }
    cout << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1384
final_rank: 10

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> edge;
typedef vector<edge> ve;
typedef vector<ve> graph;

int main(){
  int n,m,p;
  while(cin >> n >> m >> p, n){
    graph g(n);
    for(int i=0;i<m;i++){
      int a,b,c;
      cin >> a >> b >> c;
      g[a].push_back(edge(c,b));
      g[b].push_back(edge(c,a));
    }

    vi c(p);
    for(int i=0;i<p;i++)cin >> c[i];

    vi d(n,1e9), order;
    d[0] = 0;
    priority_queue< edge,vector<edge>,greater<edge> > pq;
    pq.push(edge(0,0));

    while(pq.size()){
      int dis = pq.top().first, v = pq.top().second; pq.pop();
      if(d[v] < dis)continue;
      order.push_back(v);

      for(edge e : g[v]){
	int nxtd = dis + e.first, u = e.second;
	if(d[u] > nxtd){
	  d[u] = nxtd;
	  pq.push(edge(nxtd,u));
	}
      }
    }

    vector<long double> cnt(n,0);
    cnt[n-1] = 1;
    for(int i=order.size()-1;i>=0;i--){
      int v = order[i];
      for(edge e : g[v]){
	int dis = e.first, u = e.second;
	if(d[v] == d[u] + dis)cnt[u] += cnt[v];
      }
    }

    vector<long double> prob(n,0);
    prob[0] = 1;
    for(int i=0;i<n;i++){
      int v = order[i];

      for(edge e : g[v]){
	int nxtd = d[v] + e.first, u = e.second;
	if(d[u] == nxtd){
	  prob[u] += cnt[u] / cnt[v] * prob[v];
	}
      }
    }

    for(int i=0;i<p;i++){
      cout << fixed << setprecision(9) << prob[c[i]] << endl;
    }
    cout << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1388
final_rank: 11

code_snippet: #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
#define INF (1<<28)
#define MAX 105
struct edge{int to,cost;};
struct state{
  int pos,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};
 
vector<edge> G[MAX];
int n,m,p;
 
void init(){
  for(int i=0;i<MAX;i++){
    G[i].clear();
  }
}
 
long long d[MAX][MAX];
double cnt[MAX][MAX];
void dijkstra(int si){
  for(int i=0;i<MAX;i++)d[si][i]=INF,cnt[si][i]=0;
  priority_queue<state> Q;
  d[si][si]=0;
  cnt[si][si]=1;
  Q.push((state){si,0});
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.cost>d[si][s.pos])continue;
    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      if(d[si][e.to]<s.cost+e.cost)continue;
      else if(d[si][e.to]==s.cost+e.cost){
    cnt[si][e.to]+=cnt[si][s.pos];
      }else{
    cnt[si][e.to]=cnt[si][s.pos];
    d[si][e.to]=s.cost+e.cost;
    Q.push((state){e.to,d[si][e.to]});
      }
    }
  }
}
 
int main(){
  while(1){
    cin>>n>>m>>p;
    if(n==0&&m==0&&p==0)break;
    init();
    for(int i=0;i<m;i++){
      int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
      G[a].push_back((edge){b,c});
      G[b].push_back((edge){a,c});
    }
    for(int i=0;i<n;i++)
      dijkstra(i);
 
    for(int i=0;i<p;i++){
      int a;
      scanf("%d",&a);
      if(d[0][a]+d[a][n-1]!=d[0][n-1]){
    cout<<"0.0"<<endl;
      }else{
    double x=cnt[0][a],x2=cnt[a][n-1],y=cnt[0][n-1];
    printf("%.8f\n",x/y*x2);
      }
 
 
    }
    cout<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1600
final_rank: 15

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

int N, M, C;

typedef long long ll;

struct Edge {
  int to; ll cost;
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

Graph g;

double cntpath[110][110];

struct state {
  int curr; ll cost;
  bool operator < (state const& s) const {
    return cost > s.cost;
  }
};

struct ST {
  int curr; double prob;
};

ll const INF = 1LL<<40;

int main() {
  
  while(cin >> N >> M >> C && (N|M|C)) {
    g.clear(); g.resize(N);
    
    rep(i, M) {
      int a, b; ll c; cin >> a >> b >> c;
      g[a].push_back((Edge){b, c});
      g[b].push_back((Edge){a, c});
    }
    
    ll dist[N][N];
    fill(dist[0], dist[0]+N*N, INF);
    
    rep(S, N) {
      dist[S][S] = 0;
      cntpath[S][S] = 1;
      priority_queue<state> pq;
      pq.push((state){S, dist[S][S]});
      while(!pq.empty()) {
        int curr = pq.top().curr;
        ll cost = pq.top().cost;
        pq.pop();
      
        rep(i, g[curr].size()) {
          Edge& e = g[curr][i];
          if(dist[S][e.to] == cost+e.cost) {
            cntpath[S][e.to] += cntpath[S][curr];
          }
          if(dist[S][e.to] <= cost+e.cost) { continue; }
          cntpath[S][e.to] = cntpath[S][curr];
          dist[S][e.to] = cost+e.cost;
          pq.push((state){e.to, dist[S][e.to]});
        }
      }
    }
    
    rep(i, C) {
      int q; cin >> q;
      if(dist[0][q]+dist[q][N-1] == dist[0][N-1]) {
        printf("%.10f\n", cntpath[0][q]/cntpath[0][N-1]*cntpath[q][N-1]);
      }
      else {
        printf("%.10f\n", 0.);
      }
    }
    cout << endl;
  }
  
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1652
final_rank: 17

code_snippet: #include<bits/stdc++.h>
 
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
 
using namespace std;

typedef long long ll;

struct Edge {
  int src,dst;
  ll w;
};

struct Data {
  int cur;
  ll w;
  bool operator < ( const Data &data ) const {
    if( w != data.w ) return w < data.w;
    return cur < data.cur;
  }
};

const ll LLINF = LLONG_MAX;
const int MAX_V = 110;
int V,E,Q;
vector<Edge> G[MAX_V];
ll fw[MAX_V][MAX_V];
double dp[MAX_V][2];

void compute(int type,int sp,int ep){
  vector<Data> vec;
  rep(i,V) vec.push_back((Data){i,fw[sp][i]});
  sort(vec.begin(),vec.end());
  rep(i,(int)vec.size()){
    int cur = vec[i].cur;
    rep(j,(int)G[cur].size()){
      int next = G[cur][j].dst;
      if( fw[sp][cur] + G[cur][j].w + fw[next][ep] == fw[sp][ep] ) {
        dp[next][type] += dp[cur][type];
      }
    }
  }
}

int main(){
  while( cin >> V >> E >> Q, V|E|Q ){
    rep(i,V) G[i].clear();
    rep(i,V) rep(j,V) fw[i][j] = ((i==j)?0:LLINF);
    rep(i,E) {
      int src,dst;
      ll w;
      cin >> src >> dst >> w;
      fw[src][dst] = fw[dst][src] = w;
      G[src].push_back((Edge){src,dst,w});
      G[dst].push_back((Edge){dst,src,w});
    }

    rep(k,V) rep(i,V) rep(j,V) if( fw[i][k] != LLINF && fw[k][j] != LLINF ) fw[i][j] = min(fw[i][j],
                                                                                           fw[i][k]+fw[k][j]);
    
    rep(i,MAX_V) rep(j,2) dp[i][j] = 0;
    dp[0][0] = dp[V-1][1] = 1;
    compute(0,0,V-1);
    compute(1,V-1,0);
    rep(i,Q){
      int pos;
      cin >> pos;
      printf("%.10f\n",dp[pos][0]*dp[pos][1]/dp[V-1][0]);
    } puts("");
    
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1548
final_rank: 14

code_snippet: #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
#define INF (1<<28)
#define MAX 105
struct edge{int to,cost;};
struct state{
  int pos,cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};

vector<edge> G[MAX];
int n,m,p;

void init(){
  for(int i=0;i<MAX;i++){
    G[i].clear();
  }
}

long long d[MAX][MAX];
double cnt[MAX][MAX];
void dijkstra(int si){
  for(int i=0;i<MAX;i++)d[si][i]=INF,cnt[si][i]=0;
  priority_queue<state> Q;
  d[si][si]=0;
  cnt[si][si]=1;
  Q.push((state){si,0});
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.cost>d[si][s.pos])continue;
    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      if(d[si][e.to]<s.cost+e.cost)continue;
      else if(d[si][e.to]==s.cost+e.cost){
	cnt[si][e.to]+=cnt[si][s.pos];
      }else{
	cnt[si][e.to]=cnt[si][s.pos];
	d[si][e.to]=s.cost+e.cost;
	Q.push((state){e.to,d[si][e.to]});
      }
    }
  }
}

int main(){
  while(1){
    cin>>n>>m>>p;
    if(n==0&&m==0&&p==0)break;
    init();
    for(int i=0;i<m;i++){
      int a,b,c;
      scanf("%d%d%d",&a,&b,&c);
      G[a].push_back((edge){b,c});
      G[b].push_back((edge){a,c});
    }
    for(int i=0;i<n;i++)
      dijkstra(i);

    for(int i=0;i<p;i++){
      int a;
      scanf("%d",&a);
      if(d[0][a]+d[a][n-1]!=d[0][n-1]){
	cout<<"0.0"<<endl;
      }else{
	double x=cnt[0][a],x2=cnt[a][n-1],y=cnt[0][n-1];
	printf("%.8f\n",x/y*x2);
      }


    }
    cout<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1600
final_rank: 15

code_snippet: // 20:47~

#include <bits/stdc++.h>
using namespace std;

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

struct Edge{
	int src,dst,weight;
	Edge(){}
	Edge(int s,int d,int w):src(s),dst(d),weight(w){}
};
typedef vector<vector<Edge>> Graph;

int main()
{
	for(int n,m,p;cin>>n>>m>>p && n|m|p;){
		Graph g(n);
		rep(i,m){
			int u,v,w; cin>>u>>v>>w;
			g[u].emplace_back(u,v,w);
			g[v].emplace_back(v,u,w);
		}
		
		vvi d(n,vi(n,INF));
		rep(i,n) d[i][i]=0;
		rep(i,n) for(auto e:g[i]) d[e.src][e.dst]=e.weight;
		rep(k,n) rep(i,n) rep(j,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
		
		vvd cnt(n,vd(n));
		rep(i,n) for(auto e:g[i])
			if(d[0][e.src]+e.weight+d[e.dst][n-1]==d[0][n-1])
				cnt[e.src][e.dst]=1;
		rep(k,n) rep(i,n) rep(j,n)
			cnt[i][j]+=cnt[i][k]*cnt[k][j];
		
		rep(_,p){
			int c; cin>>c;
			printf("%.9f\n",cnt[0][c]*cnt[c][n-1]/cnt[0][n-1]);
		}
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1500
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

struct Edge{
	int src,dst,weight;
	Edge(){}
	Edge(int s,int d,int w):src(s),dst(d),weight(w){}
};
typedef vector<vector<Edge>> Graph;

void chmin(int& a,int b)
{
	a=min(a,b);
}

int main()
{
	for(int n,m,s;cin>>n>>m>>s && n|m|s;){
		Graph g(n);
		rep(i,m){
			int u,v,w; cin>>u>>v>>w;
			g[u].emplace_back(u,v,w);
			g[v].emplace_back(v,u,w);
		}
		vi cs(s);
		rep(i,s) cin>>cs[i];
		
		vvi dp(n,vi(n,INF));
		rep(i,n) dp[i][i]=0;
		rep(i,n) for(auto e:g[i]) chmin(dp[e.src][e.dst],e.weight);
		rep(k,n) rep(i,n) rep(j,n) chmin(dp[i][j],dp[i][k]+dp[k][j]);
		
		vd cnt1(n,0); cnt1[0]=1;
		{
			Graph gg(n);
			rep(i,n) for(auto e:g[i]) if(dp[0][e.src]+e.weight+dp[e.dst][n-1]==dp[0][n-1])
				gg[e.src].push_back(e);
			vi is(n); iota(all(is),0);
			sort(all(is),[&](int i,int j){return dp[0][i]<dp[0][j];});
			for(auto u:is) for(auto e:gg[u]) cnt1[e.dst]+=cnt1[u];
		}
		vd cnt2(n,0); cnt2[n-1]=1;
		{
			Graph gg(n);
			rep(i,n) for(auto e:g[i]) if(dp[0][e.src]+e.weight+dp[e.dst][n-1]==dp[0][n-1])
				gg[e.dst].emplace_back(e.dst,e.src,e.weight);
			vi is(n); iota(all(is),0);
			sort(all(is),[&](int i,int j){return dp[n-1][i]<dp[n-1][j];});
			for(auto u:is) for(auto e:gg[u]) cnt2[e.dst]+=cnt2[u];
		}
		
		for(auto i:cs) printf("%.9f\n",cnt1[i]*cnt2[i]/cnt1[n-1]); puts("");
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1520
final_rank: 13

code_snippet: #include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int g[110][110];
vector<int>g2[110];
int p[11000];
int q[11000];
int r[11000];
pair<int,int> pt[110];
double dp[110];
double dp2[110];
int main(){
    int a,b,c;
    while(scanf("%d%d%d",&a,&b,&c),a){
        for(int i=0;i<a;i++)for(int j=0;j<a;j++)g[i][j]=999999999;
        for(int i=0;i<a;i++)g[i][i]=0;
        for(int i=0;i<a;i++){g2[i].clear();}
        for(int i=0;i<b;i++){
            scanf("%d%d%d",p+i,q+i,r+i);
            g[p[i]][q[i]]=g[q[i]][p[i]]=r[i];
        }
        for(int k=0;k<a;k++)for(int i=0;i<a;i++)for(int j=0;j<a;j++)
            g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
        for(int i=0;i<b;i++){
            int P=p[i];
            int Q=q[i];
            int R=r[i];
            if(g[0][P]+R==g[0][Q]&&g[Q][a-1]+R==g[P][a-1]){
                g2[P].push_back(Q);
            }
            swap(P,Q);
            if(g[0][P]+R==g[0][Q]&&g[Q][a-1]+R==g[P][a-1]){
                g2[P].push_back(Q);
            }
        }
        for(int i=0;i<110;i++)dp[i]=0;
        dp[0]=1;
        for(int i=0;i<a;i++)pt[i]=make_pair(g[0][i],i);
        std::sort(pt,pt+a);
        for(int i=0;i<a;i++){
            int at=pt[i].second;
            for(int j=0;j<g2[at].size();j++){
                dp[g2[at][j]]+=dp[at];
            }
        }
		double tot=dp[a-1];
		
        for(int i=0;i<c;i++){
            int t;scanf("%d",&t);
			for(int j=0;j<a;j++)dp2[j]=0;
			dp2[t]=1;
			for(int j=0;j<a;j++){
				int at=pt[j].second;
				for(int k=0;k<g2[at].size();k++){
					dp2[g2[at][k]]+=dp2[at];
				}
			}
			printf("%.12f\n",dp2[a-1]/tot*dp[t]);
        }
        printf("\n");
    }
}
accuracy: 1
time_ms: 10
memory_kb: 1240
final_rank: 8

code_snippet: #include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n,m,p;cin>>n>>m>>p,n;){
    double nr[100][100]={};
    int d[100][100];
    const int INF=1<<29;
    fill(d[0],d[100],INF);
    for(int i=0;i<n;i++){
      d[i][i]=0;
    }
    while(m--){
      int s,t,u;
      cin>>s>>t>>u;
      d[s][t]=d[t][s]=u;
      nr[s][t]=nr[t][s]=1;
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  int nd=d[j][i]+d[i][k];
	  if(nd<=d[j][k]){
	    if(nd<d[j][k]){
	      nr[j][k]=0;
	    }
	    d[j][k]=nd;
	    nr[j][k]+=nr[j][i]*nr[i][k];
	  }
	}
      }
    }
    while(p--){
      int c;
      cin>>c;
      cout.precision(9);
      cout<<fixed<<((c==0||c==n-1)?1:(d[0][c]+d[c][n-1]!=d[0][n-1])?0:nr[0][c]*nr[c][n-1]/nr[0][n-1])<<endl;
    }
    cout<<endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1356
final_rank: 9

code_snippet: #include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstdio>
using namespace std;

struct NODE{
	int to,cost;
	NODE(int to,int cost) : to(to) , cost(cost) {}
	NODE(){}
};
bool operator < (const NODE &a,const NODE &b){
	return a.cost > b.cost;
}
int done[110] = {};
double dp[110] = {} , rdp[110] = {};

vector<NODE> g[100];
int n,m,p;

double dfs(int x,int cst){
	if( done[x] != cst ) return 0;
	if( x == n - 1 ) return 1;
	if( dp[x] != -1 ) return dp[x];
	double ans = 0;
	for(int i = 0 ; i < g[x].size() ; i++)
		ans += dfs(g[x][i].to,cst+g[x][i].cost);
	return dp[x] = ans;
}

double rdfs(int x,int cst){
	if( done[n-1] - done[x] != cst ) return 0;
	if( x == 0 ) return 1;
	if( rdp[x] != -1 ) return rdp[x];
	double ans = 0;
	for(int i = 0 ; i < g[x].size() ; i++)
		ans += rdfs(g[x][i].to,cst+g[x][i].cost);
	return rdp[x] = ans;
}
int main(){
	while(cin >> n >> m >> p && (n||m||p) ){
		for(int i = 0 ; i < n ; i++) g[i].clear();
		for(int i = 0 ; i < m ; i++){
			int a,b,c;
			cin >> a >> b >> c;
			g[a].push_back( NODE(b,c) );
			g[b].push_back( NODE(a,c) );
		}
		for(int i = 0 ; i < 110 ; i++) done[i] = -1;
		for(int i = 0 ; i < 110 ; i++)
				dp[i] = rdp[i] = -1;
		priority_queue<NODE> Q;
		Q.push(NODE(0,0));
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if( done[q.to] != -1 ) continue;
			else done[q.to] = q.cost;
			for(int i = 0 ; i < g[q.to].size() ; i++)
				Q.push(NODE(g[q.to][i].to,q.cost+g[q.to][i].cost));
		}
		double all = dfs(0,0);
		//cout << all << endl;
		for(int i = 0 ; i < p ; i++){
			int a;
			cin >> a;
			if( done[a] == -1 ){
				printf("%.8lf\n",0.0);
			}else{
				double A = dfs(a,done[a]);
				double B = rdfs(a,done[n-1] - done[a]);
				printf("%.8lf\n",1.0 * A*B / all);
			}
		}
		cout << endl;
	}
	
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


struct Edge
{
	int to, cost;
	Edge(int to, int cost)
		: to(to), cost(cost) {}
};

vector<vector<int> > clean(const vector<vector<int> >& e)
{
	int n = e.size();
	vector<bool> on_min_path(n);
	queue<int> q;
	on_min_path[n - 1] = true;
	q.push(n - 1);
	while (!q.empty())
	{
		int cur = q.front(); q.pop();
		for (int i = 0; i < e[cur].size(); ++i)
		{
			int to = e[cur][i];
			if (!on_min_path[to])
			{
				on_min_path[to] = true;
				q.push(to);
			}
		}
	}

	vector<vector<int> > res(n);
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < e[i].size(); ++j)
			if (on_min_path[i] && on_min_path[e[i][j]])
				res[i].push_back(e[i][j]);
	return res;
}
vector<vector<int> > prev_nodes(const vector<vector<Edge> >& edges)
{
	int n = edges.size();

	const int INF = 1e7;
	vector<int> dis(n, INF);
	vector<vector<int> > prevv(n);
	priority_queue<pint, vector<pint>, greater<pint> > q;
	dis[0] = 0;
	q.push(pint(0, 0));
	while (!q.empty())
	{
		pint tt = q.top(); q.pop();
		int cur = tt.second, cost = tt.first;

		if (cost > dis[cur])
			continue;

		foreach (e, edges[cur])
		{
			int to = e->to, nc = cost + e->cost;
			if (nc < dis[to])
			{
				dis[to] = nc;
				prevv[to].clear();
				prevv[to].push_back(cur);
				q.push(pint(nc, to));
			}
			else if (nc == dis[to])
				prevv[to].push_back(cur);
		}
	}

	return clean(prevv);
}

vector<vector<int> > rev(const vector<vector<int> >& e)
{
	vector<vector<int> > res(e.size());
	for (int i = 0; i < e.size(); ++i)
		for (int j = 0; j < e[i].size(); ++j)
			res[e[i][j]].push_back(i);
	return res;
}

double in_paths(vector<double>& dp, const vector<vector<int> >& e, int v)
{
	if (dp[v] != -1)
		return dp[v];
	else if (e[v].empty())
		return dp[v] = 1;

	double res = 0;
	for (int i = 0; i < e[v].size(); ++i)
		res += in_paths(dp, e, e[v][i]);
	return dp[v] = res;
}
int main()
{
	int n, m, p;
	while (cin >> n >> m >> p, n)
	{
		vector<vector<Edge> > edges(n);
		for (int i = 0; i < m; ++i)
		{
			int a, b, c;
			cin >> a >> b >> c;
			edges[a].push_back(Edge(b, c));
			edges[b].push_back(Edge(a, c));
		}
		vector<vector<int> > prevv = prev_nodes(edges);
		//for (int i = 0; i < n; ++i)
		//{
		//	printf("%d: ", i);
		//	for (int j = 0; j < prevv[i].size(); ++j)
		//		printf("%d ", prevv[i][j]);
		//	puts("");
		//}puts("");

		vector<double> in(n, -1), out(n, -1);
		in_paths(in, prevv, n - 1);
		in_paths(out, rev(prevv), 0);

		vector<double> paths(n);
		for (int i = 0; i < n; ++i)
			if (in[i] != -1)
				paths[i] = in[i] * out[i];
		double total_paths = paths[0];

		//for (int i = 0; i < n; ++i)
		//{
		//	printf("%d: %f %f\n", i, in[i], out[i]);
		//}

		while (p--)
		{
			int c;
			cin >> c;
			
			printf("%.8f\n", paths[c] / total_paths);
		}
		puts("");
	}
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <string> 
#include <algorithm> 
#include <cfloat> 
#include <climits> 
#include <cmath> 
#include <complex> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <functional> 
#include <iostream> 
#include <map> 
#include <memory> 
#include <queue> 
#include <set> 
#include <sstream> 
#include <stack> 
#include <utility> 
#include <vector> 

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define ALL(x) (x).begin(),(x).end() 
typedef long long ll;
using namespace std; 
const double eps = 1e-10;

const int INF = 1000;

typedef int Weight;
struct Edge{
    int from, to;
    Weight weight;
    Edge(int from, int to, Weight weight) :
        from(from), to(to), weight(weight) { }
};
bool operator < (const Edge &a, const Edge &b){
    if(a.weight != b.weight) return a.weight > b.weight;
    if(a.from != b.from) return a.from > b.from;
    return  a.to > b.to;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int n, m, p;

void dijkstra(const Graph &g, int s, vector<Weight> &dist, vector<int> &prev, vector<double> &cnt){
    int n = g.size();
    dist.assign(n, INF);
    dist[s] = 0;
    prev.assign(n, -1);
    cnt.assign(n, 0);
    cnt[s] = 1;
    priority_queue<Edge> Q;     // a < b <-> a.weight > b.weight
    Q.push(Edge(-2, s, 0));
    while(!Q.empty()){
        Edge e = Q.top(); Q.pop();
        if(prev[e.to] != -1) continue;
        prev[e.to] = e.from;
        for(Edges::const_iterator i=g[e.to].begin(); i!=g[e.to].end(); ++i){    //ツマツクツδ債つェツ使ツつヲツづ按つ「ツづつォ
            if(dist[i -> to] == dist[i -> from] + i -> weight)
                cnt[i -> to] += cnt[i -> from];
            if(dist[i -> to] > dist[i -> from] + i -> weight){
                dist[i -> to] = dist[i -> from] + i -> weight;
                cnt[i -> to] = cnt[i -> from];
                Q.push(Edge(i -> from, i -> to, dist[i -> to]));
            }
        }
    }
}

void solve(Graph &g, vector<int> &c){
    vector<Weight> df, di;
    vector<int> pf, pi;
    vector<double> tf, ti;
    dijkstra(g, 0, df, pf, tf);
    dijkstra(g, n - 1, di, pi, ti);

    for(int i = 0; i < p; ++i){
        double res = 0.0;
        if(df[c[i]] + di[c[i]] == df[n - 1]){
            res = (double)tf[c[i]] * ti[c[i]] / tf[n - 1];
        }
        printf("%.9lf\n", res);
    }
    cout << endl;
}

int main(){
    while(cin >> n >> m >> p, n || m || p){
        Graph g(n);
        for(int i = 0; i < m; ++i){
            int x, y, z;
            cin >> x >> y >> z;
            g[x].push_back(Edge(x, y, z));
            g[y].push_back(Edge(y, x, z));
        }
        vector<int> c;
        for(int i = 0; i < p; ++i){
            int t;
            cin >> t;
            c.push_back(t);
        }
        solve(g, c);
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include<iostream>
#include<vector>
#include<cassert>
#include<algorithm>
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;

    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);
  }
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int N = 110;
const int M = 1000010;
const int inf = 1000000000;

struct Edge
{
    int f, t, d;
}e[M];

int point[N], next[M], ne;
int dis[2][N], q[N];
bool u[N];

void add_edge(int f, int t, int d)
{
    e[ne].f = f, e[ne].t = t, e[ne].d = d;
    next[ne] = point[f], point[f] = ne++;
}

void spfa(int s, int n, int k)
{
    int i, tmp, f, r;
    for(i = 0; i < n; ++i) {
        dis[k][i] = inf;
        u[i] = false;
    }
    dis[k][s] = 0;
    u[s] = true;
    f = 0, r = 1;
    q[f] = s;
    while(f != r) {
        tmp = q[f];
        f = (f + 1) % n;
        u[tmp] = false;
        for(i = point[tmp]; i != -1; i = next[i]) {
            if(dis[k][e[i].t] > dis[k][tmp] + e[i].d) {
                dis[k][e[i].t] = dis[k][tmp] + e[i].d;
                if(!u[e[i].t]) {
                    u[e[i].t] = true;
                    q[r] = e[i].t;
                    r = (r + 1) % n;
                }
            }
        }
    }
}

struct Node
{
    int d, id;
    double cnt;
    bool operator < (const Node &x) const {
        return d < x.d;
    }
}qi[N];

bool cmp(const Node &x, const Node &y)
{
    return x.id < y.id;
}

int qid[N];
double cnt[N];

void update(int s, int n)
{
    for(int i = 0; i < n; ++i)
        qid[qi[i].id] = i;
    qi[0].cnt = 1;
    for(int i = 0; i < n; ++i) {
        int f = qi[i].id;
        for(int j = point[f]; j != -1; j = next[j]) {
            int t = e[j].t;
            if(!u[t])   continue;
            if(dis[0][f] + e[j].d == dis[0][t])
                qi[qid[t]].cnt += qi[i].cnt;
        }
    }
    qi[0].cnt = qi[qid[n - 1]].cnt;

    for(int k = 1; k < n; ++k) {
        memset(cnt, 0, sizeof(cnt));
        cnt[0] = 1;
        for(int i = 0; i < n; ++i) {
            if(i == k)  continue;
            int f = qi[i].id;
            for(int j = point[f]; j != -1; j = next[j]) {
                int t = e[j].t;
                if(!u[t])   continue;
                if(dis[0][f] + e[j].d == dis[0][t])
                    cnt[qid[t]] += cnt[i];
            }
        }
        if(k != qid[n - 1])
            qi[k].cnt = qi[qid[n - 1]].cnt - cnt[qid[n - 1]];
    }
}

int main()
{
    int i, n, m, p, a, b, d, iid;
    while(scanf("%d%d%d", &n, &m, &p) && n + m + p) {
        ne = 0;
        memset(point, -1, sizeof(point));
        for(i = 0; i < m; ++i) {
            scanf("%d%d%d", &a, &b, &d);
            add_edge(a, b, d);
            add_edge(b, a, d);
        }
        spfa(0, n, 0);
        spfa(n - 1, n, 1);
        /*for(int j = 0; j < 2; ++j) {
            printf("********\n");
            for(i = 0; i < n; ++i) {
                printf("%d: %d\n", i, dis[j][i]);
            }
        }*/
        memset(u, false, sizeof(u));
        for(i = 0; i < n; ++i) {
            qi[i].d = dis[0][i];
            qi[i].cnt = 0, qi[i].id = i;
            if(dis[0][i] + dis[1][i] == dis[0][n - 1])
                u[i] = true;
        }
        sort(qi, qi + n);
        update(0, n);
        sort(qi, qi + n, cmp);
        while(p--) {
            scanf("%d", &iid);
            if(qi[n - 1].cnt == 0) {
                printf("0.00000000\n");
            }
            else {
                printf("%.14f\n", qi[iid].cnt * 1.0 / qi[n - 1].cnt);
            }
        }
        printf("\n");
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void shortestPath(const vector<vector<int> >& graph, int start, vector<int>& dist)
{
    int n = graph.size();
    dist.assign(n, INT_MAX);
    dist[start] = 0;
    priority_queue<pair<int,int> ,vector<pair<int,int> >, greater<pair<int,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<int, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first)
            continue;
        for(int i=0; i<n; ++i){
            if(graph[v][i] >= 0 && dist[v] + graph[v][i] < dist[i]){
                dist[i] = dist[v] + graph[v][i];
                q.push(make_pair(dist[i], i));
            }
        }
    }

    replace(dist.begin(), dist.end(), INT_MAX, -1);
}

double dfs1(vector<vector<int> >& graph, vector<int>& dist, vector<double>& num, int pos){
     if(num[pos] != -1)
         return num[pos];

     int n = graph.size();
     if(pos == n-1)
         return num[pos] = 1;

     double tmp = 0;
     for(int i=0; i<n; ++i){
         if(graph[pos][i] != -1 && dist[pos] + graph[pos][i] == dist[i])
             tmp += dfs1(graph, dist, num, i);
     }
     return num[pos] = tmp;
}

double dfs2(vector<vector<int> >& graph, vector<int>& dist, vector<double>& num, int pos){
     if(num[pos] != -1)
         return num[pos];

     int n = graph.size();
     if(pos == 0)
         return num[pos] = 1;

     double tmp = 0;
     for(int i=0; i<n; ++i){
         if(graph[i][pos] != -1 && dist[pos] == dist[i] + graph[i][pos])
             tmp += dfs2(graph, dist, num, i);
     }
     return num[pos] = tmp;
}

void solve(vector<vector<int> >& graph, vector<double>& p)
{
    int n = graph.size();
    vector<int> dist;
    shortestPath(graph, 0, dist);

    vector<double> num1(n, -1.0), num2(n, -1.0);
    dfs1(graph, dist, num1, 0);
    dfs2(graph, dist, num2, n-1);

    p.resize(n, 0.0);
    for(int i=0; i<n; ++i){
        if(num2[i] > -0.5)
            p[i] = num1[i] * num2[i] / num1[0];
    }
}

int main()
{
    for(;;){
        int n, m, p;
        cin >> n >> m >> p;
        if(n == 0)
            return 0;

        vector<vector<int> > graph(n, vector<int>(n, -1));
        for(int i=0; i<m; ++i){
            int a, b, c;
            cin >> a >> b >> c;
            graph[a][b] = graph[b][a] = c;
        }

        vector<double> prob;
        solve(graph, prob);
        for(int i=0; i<p; ++i){
            int a;
            cin >> a;
            printf("%.10f\n", prob[a]);
        }
        cout << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<vector>
#include<sstream>
#include<set>
#include<queue>
#include<algorithm>
#include<cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define fr(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair

int n,m,p,C[100];
vector<vector<pair<int,int> > > e;
int d[100];
bool v[100],u[100];
double togoal[100],prob[100];

int main(){
	while(cin>>n>>m>>p,n){
		e.clear(); e.resize(n);
		rep(i,m){
			int a,b,c; cin>>a>>b>>c;
			e[a].pb(mp(b,c)); e[b].pb(mp(a,c));
		}
		rep(i,p)cin>>C[i];
		
		rep(i,n)d[i]=1<<28; d[0]=0;
		priority_queue<pair<int,int> > Q; Q.push(mp(0,0));
		while(!Q.empty()){
			int c=Q.top().second,cc=Q.top().first; Q.pop();
			if(c==n-1)break;
			if(d[c]<-cc)continue;
			fr(i,e[c])if(d[i->first]>-cc+i->second)
			d[i->first]=-cc+i->second,Q.push(mp(cc-i->second,i->first));
		}
		
		rep(i,n)u[i]=v[i]=0;
		rep(i,n)prob[i]=0,togoal[i]=0;
		togoal[n-1]=1; v[n-1]=1;
		Q=priority_queue<pair<int,int> >(); Q.push(mp(d[n-1],n-1));
		while(!Q.empty()){
			int c=Q.top().second; Q.pop();
			fr(i,e[c])if(d[i->first]+i->second==d[c]){
				togoal[i->first]+=togoal[c];
				if(!v[i->first])v[i->first]=1,Q.push(mp(d[i->first],i->first));
			}
		}
		Q=priority_queue<pair<int,int> >(); Q.push(mp(0,0));
		prob[0]=1; u[0]=1;
		while(!Q.empty()){
			int c=Q.top().second; Q.pop();
			fr(i,e[c])if(v[i->first]&&d[i->first]==d[c]+i->second)
			{
				prob[i->first]+=prob[c]*togoal[i->first]/togoal[c];
				if(!u[i->first])u[i->first]=1,Q.push(mp(-d[i->first],i->first));
			}
		}
		rep(i,p)printf("%.7f\n",prob[C[i]]); puts("");
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include<iostream>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;
const int infty = 1<<28;

struct Node{
  vector<int> con;
  vector<int> in;
  vector<int> cost;
};

typedef vector<Node> Graph;

double topologicalSort(const Graph &G, int n, int s, int g)
{
  double numPath[n];
  int invis[n];
  bool vis[n];
  queue<int> q;
  for(int i = 0; i < n; ++i){
    invis[i] = 0;
    numPath[i] = 0.0;
    vis[i] = false;
  }
  numPath[s]=1.0;
  
  q.push(s);
  vis[s]=true;
  while(!q.empty()){
    int now = q.front();
    q.pop();
    
    for(int i = 0; i < G[now].con.size(); ++i){
      int nid = G[now].con[i];
      invis[nid]++;
      numPath[nid] += numPath[now];
      if( invis[nid] == G[nid].in.size() ){
	if( !vis[nid] ){
	  vis[nid]=true;
	  q.push( nid );
	}
      }
    }
  }
  
  return numPath[g];
}

int main()
{
  while(true){
    int n,m,p;
    cin >> n >> m >> p;
    if( n == 0 && m == 0 && p == 0 ) break;
    int c[p];
    double cPath[n];
    Graph G(n);
    Graph DAG(n);
    Graph rDAG(n);
    int d[n][n];
    
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){
	if( i == j ) d[i][j] = 0;
	else d[i][j] = infty;
      }
    }

    for(int i = 0; i < m; ++i){
      int a,b,c;
      cin >> a >> b >> c;
      G[a].con.push_back(b);
      G[a].cost.push_back(c);
      G[b].con.push_back(a);
      G[b].cost.push_back(c);
      d[a][b]=min(d[a][b],c);
      d[b][a]=min(d[b][a],c);
    }
    for(int i = 0; i < p; ++i){
      cin >> c[i];
    }
    
    for(int k = 0; k < n; ++k){
      for(int i = 0; i < n; ++i){
	for(int j = 0; j < n; ++j){
	  d[i][j] = min( d[i][j], d[i][k]+d[k][j] );
	}
      }
    }
    
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < G[i].con.size(); ++j){
	int u = i;
	int v = G[i].con[j];
	int w = G[i].cost[j];
	if( d[0][u]+w+d[v][n-1] == d[0][n-1] ){
	  DAG[u].con.push_back(v);
	  rDAG[v].con.push_back(u);
	  DAG[v].in.push_back(u);
	  rDAG[u].in.push_back(v);
	}
      }
    }

    double sgPath = topologicalSort( DAG, n, 0, n-1 );
    for(int i = 0; i < p; ++i){
      cPath[i] = topologicalSort( DAG, n, 0, c[i] );
      //cout << cPath[i] << ' ';
      cPath[i] *= topologicalSort( rDAG, n, n-1, c[i] );
      //cout << cPath[i] << endl;
      printf("%.12lf\n", cPath[i]/sgPath );
    }
    putchar('\n');
    
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1124
final_rank: 19