https://www.codechef.com/IOPC2015/problems/IOPC15L
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d",&x)
vector<int> graph[200];
int parents[200];
double color[200][200];
void DFS(int root,int b,double add){
for(int i=0;i<graph[root].size();i++){
color[graph[root][i]][b]+=add/parents[graph[root][i]];
DFS(graph[root][i],b,add/parents[graph[root][i]]);
}
}
int main(){
int t,c,m,n,p,x,y,b;
sd(t);
while(t--){
sd(c);sd(p);
for(int i=0;i<c;i++)graph[i].clear();
memset(parents,0,sizeof(int)*200);
while(p--){
sd(x);sd(y);
x--;y--;
graph[y].push_back(x);
parents[x]++;
}
sd(m);sd(n);
memset(color,0,sizeof(double)*40000);
while(m--){
sd(x);sd(b);
x--;b--;
color[x][b]=1;
DFS(x,b,1);
}
for(int i=0;i<n;i++){
double total=0;
for(int j=0;j<c;j++)total+=color[j][i];
printf("%lf ",total);
}
cout<<endl;
}
return 0;
}