Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#pragma GCC optimize("Ofast")
- //#pragma GCC optimize ("unroll-loops")
- //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
- //THESE ARE LAST DITCH EFFORTS!!!
- #include <bits/stdc++.h>
- using namespace std;
- const int mod = 998244853;
- long long binexp(long long a, long long n) {
- long long res = 1;
- while(n) {
- if(n & 1) {
- res = (res * a) % mod;
- }
- a = (a * a) % mod;
- n >>= 1;
- }
- return res;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n, m, k;
- cin >> n >> m >> k;
- vector<map<int, vector<int>>> adj(n + 1);
- while(m--) {
- int u, v, w;
- cin >> u >> v >> w;
- adj[u][v].push_back(w);
- adj[v][u].push_back(w);
- }
- vector<int> path(k);
- for(int i = 0; i < k; i++) {
- cin >> path[i];
- }
- long long ans = 0;
- for(int i = 1; i < k; i++) {
- int sz = (int)adj[path[i - 1]][path[i]].size();
- if(sz == 0) {
- cout << "Stupid Msacywy!\n";
- return 0;
- }
- long long cur = binexp(10, k - i - 1);
- for(auto e : adj[path[i - 1]][path[i]]) {
- long long ee = e;
- ans += ((cur * ee) % mod) * (binexp(sz, mod - 2)) % mod;
- ans %= mod;
- }
- }
- cout << ans << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement