-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13158.cpp
58 lines (46 loc) · 974 Bytes
/
13158.cpp
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
using namespace std;
vector<pair<int,char> > v[1001];
string s;
int n,m;
double d[1001];
int ind[1001][26];
int main(){
ios_base::sync_with_stdio(0);
cin >> n >> m;
for(int i=0 ;i<m ; i++){
int a,b;
char c;
cin >> a >> b >> c;
v[a].push_back(pair<int,char>(b,c));
v[b].push_back(pair<int,char>(a,c));
ind[a][c-'A']++;
ind[b][c-'A']++;
}
cin >> s;
d[1] = 1;
int len = s.length();
for(int i=0 ;i<len ;i++){
double nx[1001]={0.0,};
for(int j=1 ; j<n; j++){
char cur = s[i];
int go = ind[j][cur-'A'];
if(!go) nx[j] += d[j];
else{
for(auto k : v[j]){
if(k.second==cur) nx[k.first] += d[j]/((double)go);
}
}
}
nx[n] += d[n];
for(int l=0 ;l<=n;l++) d[l] = nx[l];
}
cout.precision(5);
cout << d[n]*(1.0*100) << '\n';
return 0;
}