include iostream include vector include fstream include iomanip includ

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
#include <iostream>
#include <vector>
#include <fstream>
#include <iomanip>
#include<cmath>
using namespace std;
double pow1(double x,int n)
{
if (n == 1)
return x;
if (n == 0)
return 1;
double c = pow1(x, n / 2);
c *= c;
if (n % 2== 1)
c *= x;
return c;
}
vector<int> to, longTo;
vector<int> W;
int cnt = 1000;
vector<double> ans;
vector<double> longAns;
int main()
{
ifstream cin("input.txt");
ofstream cout("output.txt");
int n, m, k;
cin >> n >> m>> k;
to.resize(n);
double x;
cin >> x;
double longx = pow(x, cnt);
longTo.resize(n);
ans.resize(n);
longAns.resize(n);
W.resize(n, 1000000001);
for (int i = 0; i < m; ++i)
{
int a,b, w;
cin >> a >> b >> w;
--a;
--b;
if (W[a] > w)
{
W[a] = w;
to[a] = b;
}
if (W[b] > w)
{
W[b] = w;
to[b] = a;
}
}
for (int i = 0; i < n; ++i)
{
int a = i;
// cout << a + 1<< " " << to[a] + 1 << endl;
for (int i1 = 0; i1 < cnt ; ++i1)
{
a = to[a];
}
longTo[i] = a;
}
for (int i = 0; i < k; ++i)
{
int v, t;
double p;
cin >> v >> p >> t;
int v1 = v;
--v;
for (int i1 = 0; i1 < t / cnt; ++i1)
{
longAns[v] += p;
p *= longx;
v = longTo[v];
}
for (int i1 = 0; i1 < t % cnt; ++i1)
{
ans[v] += p;
// cout << v << " " << " ";
v = to[v];
p *= x;
if (p < 1e-15)
break;
}//cout << endl;
}
for (int i = 0; i < n; ++i)
{
int v= i;
double p = longAns[i];
//cout << p << endl;
for (int i1 = 0; i1 < cnt; ++i1)
{
ans[v] += p;
p *= x;
v = to[v];
}
cout << fixed << setprecision(10) << ans[i] << endl;
}
return 0;
}