// g++-15 1.cpp -std=c++23 -O2 -I . // 壊れるとき // conda deactivate # 何回か必要なことあり // hash -r # コマンドキャッシュクリア // which -a ld // ld の先頭が /usr/bin/ld になればそのままコンパイルしてOK #include using namespace std; #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") // #include // #include // #include // using namespace __gnu_pbds; #include #include using namespace atcoder; using ll = long long; using ld = long double; using vi = vector; using vvi = vector; using vll = vector; using vvll = vector; using vld = vector; using vvld = vector; using vst = vector; using vvst = vector; #define fi first #define se second #define pb push_back #define eb emplace_back #define pq_big(T) priority_queue,less> #define pq_small(T) priority_queue,greater> #define all(a) a.begin(),a.end() #define rep(i,start,end) for(ll i=start;i<(ll)(end);i++) #define per(i,start,end) for(ll i=start;i>=(ll)(end);i--) #define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end()) template istream& operator>>(istream& is, pair &v){ is >> v.first >> v.second; return is; } template ostream& operator<<(ostream& os, pair &v){ os << v.first << " " << v.second << "\n"; return os; } template istream& operator>>(istream& is, vector &v){ for(T &e: v) is >> e; return is; } template ostream& operator<<(ostream& os, vector v){ for(int i=0;i>> &g,string &s){ // cout<; pq_small(T) que; que.push({0,0,0}); while(!que.empty()){ auto [time,pos,ok]=que.top(); que.pop(); if(time>dp[pos][ok])continue; for(auto [nxt,cst]:g[pos]){ int nok=ok; if(nok<4&&tar[nok]==s[nxt])nok++; if(dp[nxt][nok]>time+cst){ dp[nxt][nok]=time+cst; que.push({time+cst,nxt,nok}); } } } ll ans=1e18; rep(i,0,n)ans=min(ans,dp[i][4]); return ans; } void solve(){ int n,m;cin>>n>>m; vector>> g(n); rep(i,0,m){ int u,v; ll c; cin>>u>>v>>c; u--;v--; g[u].emplace_back(v,c); } string s;cin>>s; ll ans=1e18; vi cs; rep(i,0,n){ if(s[i]=='C')cs.emplace_back(i); } rep(t,0,50){ for(int pos:cs){ if(grr(0,2)==0){ s[pos]='c'; } } ans=min(ans,work(n,g,s)); for(int pos:cs){ s[pos]='C'; } } if(ans==1e18)ans=-1; cout<>t; while(t--){ solve(); } }