Advertisement
cosenza987

Untitled

May 13th, 2022
944
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. //#pragma GCC optimize("Ofast")
  2. //#pragma GCC optimize ("unroll-loops")
  3. //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  4. //THESE ARE LAST DITCH EFFORTS!!!
  5.  
  6. #include <bits/stdc++.h>
  7.  
  8. using namespace std;
  9.  
  10. const int mod = 998244853;
  11.  
  12. long long binexp(long long a, long long n) {
  13.     long long res = 1;
  14.     while(n) {
  15.         if(n & 1) {
  16.             res = (res * a) % mod;
  17.         }
  18.          a = (a * a) % mod;
  19.          n >>= 1;
  20.     }
  21.     return res;
  22. }
  23.  
  24. int main() {
  25.     ios_base::sync_with_stdio(false);
  26.     cin.tie(0);
  27.     int n, m, k;
  28.     cin >> n >> m >> k;
  29.     vector<map<int, vector<int>>> adj(n + 1);
  30.     while(m--) {
  31.         int u, v, w;
  32.         cin >> u >> v >> w;
  33.         adj[u][v].push_back(w);
  34.         adj[v][u].push_back(w);
  35.     }
  36.     vector<int> path(k);
  37.     for(int i = 0; i < k; i++) {
  38.         cin >> path[i];
  39.     }
  40.     long long ans = 0;
  41.     for(int i = 1; i < k; i++) {
  42.         int sz = (int)adj[path[i - 1]][path[i]].size();
  43.         if(sz == 0) {
  44.             cout << "Stupid Msacywy!\n";
  45.             return 0;
  46.         }
  47.         long long cur = binexp(10, k - i - 1);
  48.         for(auto e : adj[path[i - 1]][path[i]]) {
  49.             long long ee = e;
  50.             ans += ((cur * ee) % mod) * (binexp(sz, mod - 2)) % mod;
  51.             ans %= mod;
  52.         }
  53.     }
  54.     cout << ans << "\n";
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement