File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` cpp
2+
3+ #include < iostream>
4+ #include < vector>
5+ #include < algorithm>
6+ using namespace std ;
7+
8+ int main () {
9+ cin.tie(0)->sync_with_stdio(0);
10+
11+ int N;
12+ cin >> N;
13+ char col[1001]{};
14+ for (int i = 1; i <= N; i++) cin >> col[i];
15+
16+ vector<vector<pair<int, char>>> V(1001);
17+ int M, K;
18+ for (cin >> M >> K; K--;) {
19+ int a, b;
20+ char c;
21+ cin >> a >> b >> c;
22+ V[a].emplace_back(b, c);
23+ V[b].emplace_back(a, c);
24+ }
25+
26+ vector<int> D(M + 1, -1);
27+ D[1] = 0;
28+ for (int t = 1; t <= N; t++) {
29+ vector<int> ND(M + 1, -1);
30+ for (int i = 1; i <= M; i++) {
31+ if (D[i] == -1) continue;
32+ for (auto &[x, c] : V[i]) {
33+ int val = D[i] + (c == col[t] ? 10 : 0);
34+ ND[x] = max(ND[x], val);
35+ }
36+ }
37+ D = ND;
38+ }
39+ int ans = *max_element(D.begin(), D.end());
40+ cout << (ans == -1 ? 0 : ans);
41+
42+ }
43+
44+ ```
You can’t perform that action at this time.
0 commit comments