malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int n, p, l, r, K;   long long int gt[100005], rev[100005], gt1[100005];   long long int mu(long long int a, long long int n, long long int K) {     if (n == 0) return 1;     long long int q = mu(a, n / 2, K);     if (n % 2 == 0) return q * q % K;     return q * q % K * a % K;   }   long long int Combi(long long int n, long long int k, long long int p) {     if (n < k || k < 0) return 0;     long long int u = gt1[n] - gt1[n - k] - gt1[k];     long long int res = gt[n] * rev[k] % K * rev[n - k] % K;     res = res * mu(p, u, K) % K;     return res;   }   long long int solve(long long int p, long long int k) {     K = 1;     long long int phi = 1;     for (int i = 1; i <= k; i++) K *= p;     phi = K / p * (p - 1);     gt[0] = rev[0] = 1;     for (int i = 1; i <= 100000; i++) {       gt1[i] = gt1[i - 1];       int j = i;       while (j % p == 0) {         j /= p;         gt1[i]++;       }       gt[i] = gt[i - 1] * 1ll * j % K;       rev[i] = mu(gt[i], phi - 1, K);     }     long long int res = 0;     for (int m = 1; m <= n; m++) {       int u = (m + l - 1) / 2 + 1;       int v = (m + r) / 2;       res =           (res + Combi(n, m, p) * (Combi(m, u, p) - Combi(m, v + 1, p)) % K + K) %           K;     }     return res;   }   vector<pair<long long int, long long int> > divi;   long long int extended_euclid(long long int a, long long int b,                                 long long int &x, long long int &y) {     long long int xx = y = 0;     long long int yy = x = 1;     while (b) {       long long int q = a / b;       long long int t = b;       b = a % b;       a = t;       t = xx;       xx = x - q * xx;       x = t;       t = yy;       yy = y - q * yy;       y = t;     }     return a;   }   long long int CRT(long long int m1, long long int r1, long long int m2,                     long long int r2) {     long long int s, t;     extended_euclid(r1, r2, s, t);     long long int K = r1 * r2;     long long int res = (m2 - m1) * s % K * r1 % K;     res = (res + m1 + K) % K;     return res;   }   long long int val[100005];   long long int mod[100005];   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> p >> l >> r;     if (p == 1) {       cout << 0 << endl;       return 0;     }     for (int i = 2; i <= p / i; i++) {       if (p % i == 0) {         int cnt = 0;         while (p % i == 0) {           p /= i;           cnt++;         }         divi.push_back(pair<long long int, long long int>(i, cnt));       }     }     if (p > 1) divi.push_back(pair<long long int, long long int>(p, 1));     for (int i = 0; i < divi.size(); i++) {       val[i] = solve(divi[i].first, divi[i].second);       mod[i] = 1;       for (int j = 1; j <= divi[i].second; j++) mod[i] *= divi[i].first;     }     long long int res = val[0];     long long int M = mod[0];     for (int i = 1; i < divi.size(); i++) {       res = CRT(res, M, val[i], mod[i]);       M *= mod[i];     }     if (l == 0) res = (res + 1) % M;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int s, n, m, t, x, y;   vector<int> ord;   vector<vector<int>> g;   bool vis[200010];   void dfs(int c) {     vis[c] = true;     for (auto &v : g[c]) {       if (!vis[v]) dfs(v);     }     ord.push_back(c);   }   int main() {     std::istream::sync_with_stdio(false);     cin >> s;     while (s--) {       cin >> n >> m;       vector<pair<int, int>> edges;       g = vector<vector<int>>(n + 1);       for (int i = 0; i < m; i++) {         cin >> t >> x >> y;         if (t == 1) {           g[x].push_back(y);         }         edges.emplace_back(x, y);       }       ord.clear();       memset(vis, 0, sizeof(vis));       for (int i = 1; i <= n; i++) {         if (!vis[i]) dfs(i);       }       vector<int> pos(n + 1);       reverse(ord.begin(), ord.end());       for (int i = 0; i < n; i++) {         pos[ord[i]] = i;       }       bool flag = false;       for (int i = 1; i <= n; i++) {         for (auto &v : g[i]) {           if (pos[i] > pos[v]) flag = true;         }       }       if (flag) {         cout <<  NO  << endl;         continue;       } else {         cout <<  YES  << endl;         for (auto &v : edges) {           if (pos[v.first] < pos[v.second]) {             cout << v.first <<     << v.second << endl;           } else {             cout << v.second <<     << v.first << endl;           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, l, top, tmp, m, c[12];   bool opt[12][11][1 << 13];   void Search(int t, int v, int sum, int u, int i) {     if (v < 0) return;     if (sum >= v) opt[t][sum - v][u | (1 << t)] = 1;     if (i >= t) return;     if (((u >> i) & 1) == 1 && c[i] + 1 < c[t])       Search(t, v - c[i], sum, u ^ (1 << i), i + 1);     Search(t, v, sum, u, i + 1);   }   bool Check() {     for (int i = 0; i < l; i++)       if (c[i] == 2) return 0;     return 1;   }   int main() {     scanf( %d , &n);     l = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &tmp);       if (tmp > 1) c[l++] = tmp;     }     if (l > n / 2) {       printf( NO n );       return 0;     }     if (l == 0) {       if (n > 1)         printf( NO n );       else         printf( YES n );       return 0;     }     sort(c, c + l);     top = n - l - c[0] + 1;     opt[0][top][1] = 1;     for (int i = 1; i < l; i++)       for (int t = 0; t <= top; t++) {         m = 1 << i;         for (int u = 0; u < m; u++)           if (opt[i - 1][t][u]) Search(i, c[i] - 1, t, u, 0);       }     if (opt[l - 1][0][1 << (l - 1)] && Check())       printf( YES n );     else       printf( NO n );   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[100010];   long long ans = 0;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int Q = 0; Q < 20; Q++) {       for (int j = 1; j <= n; j++)         if (a[j] & (1 << Q)) {           int k = 0;           for (k = j; k <= n && (a[k] & (1 << Q)); k++)             ;           k--;           ans += ((long long)(k - j + 1) * (k - j + 2) / 2) << Q;           j = k;         }     }     for (int P = 1; P <= m; P++) {       int p, v;       scanf( %d%d , &p, &v);       for (int Q = 0; Q < 20; Q++)         if ((a[p] & (1 << Q)) ^ (v & (1 << Q))) {           int l, r;           for (l = p - 1; l && (a[l] & (1 << Q)); l--)             ;           for (r = p + 1; r <= n && (a[r] & (1 << Q)); r++)             ;           l = p - l;           r -= p;           if ((v >> Q) & 1)             ans += ((long long)l * r) << Q;           else             ans -= ((long long)l * r) << Q;         }       a[p] = v;       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     char c;     cin >> n >> m;     vector<int> rows(n), cols(m);     vector<vector<bool> > A(n);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         cin >> c;         if (c ==  * ) {           A[i].push_back(true);           rows[i]++;           cols[j]++;         } else           A[i].push_back(false);       }     long long res = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (A[i][j]) res += (cols[j] - 1) * (rows[i] - 1);     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<vector<int>> t(n);     for (int i = 0; i < m; ++i) {       int x, y;       scanf( %d %d , &x, &y);       --x, --y;       t[x].push_back(y);       t[y].push_back(x);     }     vector<int> dist(n * n, -1);     vector<pair<int, int>> parent(n * n, make_pair(-1, -1));     vector<bool> order(n * n, false);     queue<pair<int, int>> q;     q.push(make_pair(0, n - 1));     dist[n - 1] = 0;     while (!q.empty()) {       auto p = q.front();       q.pop();       if (p.first == n - 1 && p.second == 0) {         int len = dist[(n - 1) * n];         printf( %d n , len);         vector<int> r1, r2;         r1.push_back(n - 1);         r2.push_back(0);         int pos1 = n - 1, pos2 = 0;         while (pos1 != 0 || pos2 != n - 1) {           int tmp = pos1;           pos1 = parent[pos1 * n + pos2].first;           pos2 = parent[tmp * n + pos2].second;           r1.push_back(pos1);           r2.push_back(pos2);         }         for (int i = len; i >= 0; --i) printf( %d  , r1[i] + 1);         printf(  n );         for (int i = len; i >= 0; --i) printf( %d  , r2[i] + 1);         printf(  n );         return 0;       }       for (auto i : t[p.first]) {         if (order[i * n + p.second]) continue;         order[i * n + p.second] = true;         for (auto j : t[p.second]) {           if (i != j && dist[i * n + j] == -1) {             parent[i * n + j] = p;             dist[i * n + j] = dist[p.first * n + p.second] + 1;             q.push(make_pair(i, j));           }         }       }     }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mo = 1e9 + 7;   const int N = 200005;   map<int, int> mx, my;   int n, x, y, dx, dy, cnt, answer;   int parent[N], Size[N];   bool flag[N];   int get_parent(int x) {     if (parent[x] == x) {       return x;     } else {       return get_parent(parent[x]);     }   }   int main() {     cin >> n;     for (int i = 1; i <= 2 * n; ++i) {       parent[i] = i;       Size[i] = 1;     }     for (int i = 1; i <= n; ++i) {       cin >> x >> y;       if (mx.find(x) != mx.end()) {         dx = mx[x];       } else {         dx = mx[x] = ++cnt;       }       if (my.find(y) != my.end()) {         dy = my[y];       } else {         dy = my[y] = ++cnt;       }       dx = get_parent(dx);       dy = get_parent(dy);       if (dx == dy) {         flag[dx] = 1;       } else {         if (Size[dx] > Size[dy]) swap(dx, dy);         parent[dx] = dy;         Size[dy] += Size[dx];         flag[dy] |= flag[dx];       }     }     answer = 1;     for (int i = 1; i <= cnt; ++i) {       if (get_parent(i) == i) {         int temp = 1;         for (int j = 1; j <= Size[i]; ++j) {           temp = temp * 2 % mo;         }         if (!flag[i]) --temp;         answer = (long long)answer * temp % mo;       }     }     cout << answer << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, x;     cin >> n >> x;     int mins = 0;     int prevr = 1;     for (int i = 0; i < int(n); i++) {       int l, r;       cin >> l >> r;       mins += ((l - prevr) % x + ((r - l) + 1));       prevr = r + 1;     }     cout << mins << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     long long int res = 1;     a %= 1000000007;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   long long int modInverse(long long int a) { return power(a, 1000000007 - 2); }   const int N = 500023;   bool compare(long long int x, long long int y) { return x > y; }   void solve() {     vector<int> primes = {         2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,  41,  43,         47,  53,  59,  61,  67,  71,  73,  79,  83,  89,  97,  101, 103, 107,         109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,         191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263,         269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349,         353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,         439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521,         523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613,         617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,         709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809,         811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887,         907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};     int n, value, nocolor = 1, colored = 0;     cin >> n;     vector<pair<int, int>> color;     for (int i = 0; i < n; i++) {       cin >> value;       color.push_back(make_pair(value, 0));     }     for (int i = 0; i < primes.size(); i++) {       for (int j = 0; j < n; j++) {         if ((color[j].first % primes[i] == 0) && (color[j].second == 0)) {           color[j].second = nocolor;           colored = 1;         }       }       if (colored) {         nocolor++;       }       colored = 0;     }     cout << nocolor - 1 << endl;     for (int i = 0; i < n; i++) {       cout << color[i].second <<    ;     }     cout << endl;     return;   }   int main() {     {       ios ::sync_with_stdio(false);       cin.tie(0);       cout.tie(0);     };     int T;     cin >> T;     int t = 0;     while (t++ < T) {       solve();     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100001], t, l, r;   int _gcd[262144][19], _min[262144][19], _num[262144][19];   int gcd(int x, int y) {     if (x < y) swap(x, y);     if (y == 0) return x;     int r = x % y;     return gcd(y, r);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       _min[i][0] = a[i];       _gcd[i][0] = a[i];       _num[i][0] = 1;     }     for (int k = 1; k <= 18; k++) {       for (int i = 1; i <= n; i++) {         if (_min[i][k - 1] == _min[i + (1 << (k - 1))][k - 1]) {           _min[i][k] = _min[i][k - 1];           _num[i][k] = _num[i][k - 1] + _num[i + (1 << (k - 1))][k - 1];         } else if (_min[i][k - 1] < _min[i + (1 << (k - 1))][k - 1]) {           _min[i][k] = _min[i][k - 1];           _num[i][k] = _num[i][k - 1];         } else {           _min[i][k] = _min[i + (1 << (k - 1))][k - 1];           _num[i][k] = _num[i + (1 << (k - 1))][k - 1];         }       }     }     for (int k = 1; k <= 18; k++)       for (int i = 1; i <= n; i++)         _gcd[i][k] = gcd(_gcd[i][k - 1], _gcd[i + (1 << (k - 1))][k - 1]);     scanf( %d , &t);     for (int j = 1; j <= t; j++) {       scanf( %d , &l);       scanf( %d , &r);       int tmp = r - l + 1;       int k = log2(r - l + 1);       int GCD = gcd(_gcd[l][k], _gcd[r - (1 << k) + 1][k]);       int ans = 0;       int pos = l;       for (int i = 0; i <= 20; i++) {         if ((tmp & (1 << i)) > 0) {           if (_min[pos][i] == GCD) ans += _num[pos][i];           pos += (1 << i);         }       }       printf( %d n , tmp - ans);     }   }
#include <bits/stdc++.h>   using namespace std;   int dp[2005][2005][2][2];   int m, d, mod = 1e9 + 7;   string a, b;   int solve(int i, int mm, bool aa, bool bb) {     if (i == a.size()) return !mm;     int &x = dp[i][mm][aa][bb];     if (x != -1) return x;     x = 0;     for (int j = 0; j <= 9; j++) {       if (i % 2 && j != d || !(i % 2) && j == d) continue;       if (!aa && a[i] -  0  > j || !bb && b[i] -  0  < j) continue;       bool na = aa | a[i] -  0  < j, nb = bb | b[i] -  0  > j;       x = (x + solve(i + 1, (mm * 10 + j) % m, na, nb)) % mod;     }     return x;   }   int main() {     cin >> m >> d >> a >> b;     memset(dp, -1, sizeof dp);     cout << solve(0, 0, 0, 0);   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long linf = 1e18;   const double pi = acos(-1.0);   const int MAXN = 150000 + 10;   const int MAXM = 1e5 + 10;   const double eps = 1e-8;   bool du[MAXN];   vector<int> g[MAXN];   bool vis[MAXN];   int sum;   bool flag;   void dfs(int u, int num) {     if (!flag) return;     vis[u] = 1;     ++sum;     for (int i = 0; i < g[u].size(); ++i) {       int v = g[u][i];       if (vis[v]) continue;       if (num != g[v].size()) {         flag = 0;         return;       }       dfs(v, num);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     while (m--) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     flag = 1;     for (int i = 1; i <= n; ++i) {       if (!vis[i]) {         sum = 0;         dfs(i, g[i].size());         if (g[i].size() != sum - 1) flag = 0;       }       if (!flag) break;     }     puts(flag ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> t;     while (t--) {       string s;       cin >> s;       s =  0  + s;       s = s +  0 ;       for (int i = 1; i <= s.size(); i++) {         if (s[i] ==  ? ) {           if (s[i - 1] ==  a ) {             if (s[i + 1] ==  b ) {               s[i] =  c ;             } else {               s[i] =  b ;             }           } else {             if (s[i - 1] ==  b ) {               if (s[i + 1] ==  a ) {                 s[i] =  c ;               } else {                 s[i] =  a ;               }             } else {               if (s[i + 1] ==  b ) {                 s[i] =  a ;               } else {                 s[i] =  b ;               }             }           }         }       }       bool b = 1;       for (int i = 1; i <= s.size(); i++) {         if (s[i] == s[i - 1]) {           b = 0;         }       }       if (b) {         for (int i = 1; i <= s.size() - 2; i++) {           cout << s[i];         }       } else {         cout <<  -1 ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mas[21][21];   int n, m;   inline bool checkarr() {     for (int i = 0; i < n; i++) {       int wrongs = 0;       for (int j = 0; j < m; j++) {         if (mas[i][j] != j + 1) wrongs++;         if (wrongs > 2) return false;       }     }     return true;   }   inline void swapa(int a, int b) {     for (int j = 0; j < n; j++) {       int t = mas[j][a];       mas[j][a] = mas[j][b];       mas[j][b] = t;     }   }   int main() {     cin >> n >> m;     int i, j;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         cin >> mas[i][j];       }     }     if (checkarr()) {       cout <<  YES ;       return 0;     }     for (i = 0; i < m; i++) {       for (j = i + 1; j < m; j++) {         swapa(i, j);         if (checkarr()) {           cout <<  YES ;           return 0;         }         swapa(i, j);       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mxN = 1e5 + 5;   const long long INF = 1e18;   const long long mod = 1e9 + 7;   signed main() {     long long n;     cin >> n;     vector<string> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     map<long long, long long> o, c;     long long per = 0;     for (long long i = 0; i < n; i++) {       string s = v[i];       stack<long long> st;       for (auto x : s) {         if (st.empty()) {           st.push(x);         } else {           if (x ==  ) ) {             if (st.top() ==  ( )               st.pop();             else               st.push(x);           } else             st.push(x);         }       }       if (st.empty())         per++;       else {         long long open = 0, closing = 0;         while (!st.empty()) {           if (st.top() ==  ) )             open++;           else             closing++;           st.pop();         }         if (open == 0) {           c[closing]++;         }         if (closing == 0) {           o[open]++;         }       }     }     long long ans = per / 2;     for (auto x : o) {       ans += min(x.second, c[x.first]);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int a, c, d[205], f, n, b, x, i;   string s, s1, s11, s12;   char i1, i2, j;   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> s1;       b = s1.size();       c = c + b;       s = s +  % ;       s = s + s1;     }     c = c + n - 1;     for (i1 =  a ; i1 <=  z ; i1++) {       s1 = i1;       x = s.find(s1);       if (x == -1) {         cout << s1;         return 0;       }     }     for (i1 =  a ; i1 <=  z ; i1++) {       for (i2 =  a ; i2 <=  z ; i2++) {         s11 = i1;         s12 = i2;         s1 = s11 + s12;         x = s.find(s1);         if (x == -1) {           cout << s1;           return 0;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   vector<int> cur;   unordered_set<long long> bad;   unordered_set<int> was;   void err() {     cout <<  impossible  << endl;     exit(0);   }   void go(int x) {     cur.push_back(x);     vector<int> g;     for (auto it = was.begin(); it != was.end(); it++)       if (bad.count(x * 1000000ll + (*it)) == 0) g.push_back(*it);     for (int i = 0; i < g.size(); i++) was.erase(g[i]);     for (int i = 0; i < g.size(); i++) go(g[i]);   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       bad.insert(x * 1000000ll + y);       bad.insert(y * 1000000ll + x);     }     for (int i = 1; i < n; i++) was.insert(i);     vector<vector<int> > comps;     for (int i = 1; i < n; i++)       if (was.count(i)) {         cur.clear();         was.erase(i);         go(i);         comps.push_back(cur);       }     int sum = 0;     for (int i = 0; i < comps.size(); i++) {       int cnt = 0;       for (int j = 0; j < comps[i].size(); j++)         if (bad.count(comps[i][j]) == 0) cnt++;       if (cnt == 0) err();       sum += cnt;     }     if (k < comps.size() || k > sum) err();     cout <<  possible  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int n, k, a[222], i;     cin >> n >> k;     for (i = 1; i <= 2 * n + 1; i++) {       cin >> a[i];     }     for (i = 2; i <= 2 * n; i += 2) {       if ((a[i] - a[i - 1] > 1) && (a[i] - a[i + 1] > 1) && k > 0) {         a[i]--;         k--;       }     }     for (i = 1; i <= 2 * n + 1; i++) {       cout << a[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename Tp>   inline void read(Tp &x) {     static bool neg;     static char c;     x = 0, neg = 0, c = getchar();     for (; !isdigit(c); c = getchar()) {       if (c ==  - ) {         neg = 1;       }     }     for (; isdigit(c); c = getchar()) {       x = x * 10 + c -  0 ;     }     if (neg) {       x = -x;     }   }   const int INF = 0x3f3f3f3f;   const int N = 3e3 + 5;   const int M = 2e4 + 5;   const int K = 1e5 + 5;   int vis[N][N], dp[N][N];   int n, m, k;   int head[N], E = 0;   struct Edge {     int to, next;   } e[M * 2];   inline void addEdge(int u, int v) {     e[++E] = (Edge){v, head[u]};     head[u] = E;   }   namespace Trie {   unordered_map<int, unordered_map<int, unordered_set<int>>> store;   inline void set(int a, int b, int c) { store[a][b].insert(c); }   inline bool get(int a, int b, int c) { return (bool)store[a][b].count(c); }   }  // namespace Trie   int main() {     read(n), read(m), read(k);     for (int i = 0, u, v; i < m; ++i) {       read(u), read(v);       addEdge(u, v);       addEdge(v, u);     }     for (int i = 0, a, b, c; i < k; ++i) {       read(a), read(b), read(c);       Trie::set(a, b, c);     }     memset(vis, -1, sizeof(vis));     memset(dp, 0x3f, sizeof(dp));     dp[0][1] = 0;     queue<pair<int, int>> q;     q.emplace((pair<int, int>){0, 1});     while (!q.empty()) {       pair<int, int> u = q.front();       q.pop();       int a = u.first, b = u.second, c;       for (int i = head[b]; i; i = e[i].next) {         c = e[i].to;         if (vis[b][c] == -1) {           if (!Trie::get(a, b, c)) {             vis[b][c] = a;             dp[b][c] = dp[a][b] + 1;             q.emplace((pair<int, int>){b, c});           }         }       }     }     int ans = INF, ansPos;     for (int i = 1; i <= n; ++i) {       if (dp[i][n] < ans) {         ans = dp[i][n];         ansPos = i;       }     }     if (ans == INF) {       puts( -1 );       return 0;     } else {       printf( %d n , ans);       vector<int> vec;       vec.emplace_back(n);       vec.emplace_back(ansPos);       int u = ansPos, v = n;       while (u != 1) {         int t = v;         v = u;         u = vis[u][t];         vec.emplace_back(u);       }       for (auto it = vec.rbegin(); it != vec.rend(); ++it) {         printf( %d  , *it);       }     }   }