malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   template <class T>   inline void read(T &x) {     x = 0;     char c = getchar();     bool flag = 0;     while (!isdigit(c)) {       if (c ==  - ) flag = 1;       c = getchar();     }     while (isdigit(c)) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     x = flag ? -x : x;   }   template <class T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x >= 10) write(x / 10);     putchar(x % 10 +  0 );   }   const int maxn = 5e5 + 10;   const int mod = 998244353;   struct Edge {     int next, ed;   };   Edge e[maxn * 2];   int head[maxn], cnt;   void addEdge(int st, int ed) {     e[cnt].ed = ed;     e[cnt].next = head[st];     head[st] = cnt++;   }   bool vis[maxn];   int sum[maxn], d[maxn];   int ansl[maxn], ansr[maxn];   void get(int k) {     sum[k] = 1;     for (int i = head[k]; i != -1; i = e[i].next) {       int ed = e[i].ed;       if (sum[ed] == 0) {         get(ed);         sum[k] += sum[ed];         ++d[k];       }     }   }   void dfs(int k, int l, int r) {     vis[k] = 1;     ansr[k] = l + d[k];     int c = l, temp = r;     for (int i = head[k]; i != -1; i = e[i].next) {       int ed = e[i].ed;       if (!vis[ed]) {         ansl[ed] = c;         ++c;         dfs(ed, temp - sum[ed] * 2 + 2, temp);         temp -= sum[ed] * 2 - 1;       }     }   }   int main() {     int n;     read(n);     memset(head, -1, sizeof(head));     for (int i = 1; i < n; ++i) {       int st, ed;       scanf( %d %d , &st, &ed);       addEdge(st, ed);       addEdge(ed, st);     }     get(1);     ansl[1] = 1;     dfs(1, 2, n * 2);     for (int i = 1; i <= n; ++i) {       printf( %d %d n , ansl[i], ansr[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const long long LL_INF = 1ll * INF * INF;   const int MAX_N = 1000000 + 7;   template <typename T>   inline void addmod(T& a, const long long& b, const int& MOD = INF) {     a = (a + b) % MOD;     if (a < 0) a += MOD;   }   const int mod = INF;   long long f[MAX_N];   int n;   vector<int> adj[MAX_N];   vector<int> rev[MAX_N];   long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }   vector<int> divisors[MAX_N];   void init() {     for (int i = 1; i < MAX_N; ++i)       if (!rev[i].empty()) {         for (int j = i; j < MAX_N; j += i) divisors[j].push_back(i);       }   }   class FenWickTree {    public:     void update(int x, int val) {       for (int t = x; t < MAX_N; t += t & -t) {         tree[t] += val;       }     }     int get(int x) {       int res = 0;       for (int t = x; t > 0; t -= t & -t) {         res += tree[t];       }       return res;     }       private:     static const int MAX_N = ::MAX_N + 7;     int tree[MAX_N];   } fenwickTree;   int level[MAX_N];   int low[MAX_N], high[MAX_N];   void dfs(int u) {     static int cnt = 0;     low[u] = ++cnt;     for (int v : adj[u]) {       level[v] = level[u] + 1;       dfs(v);       f[u] += f[v];     }     high[u] = cnt;   }   bool check(int d) {     if (d == 1) return true;     if (f[0] % d) return false;     long long sum = f[0] / d;     int cnt = 0;     for (int c : divisors[d])       if (!rev[c].empty()) {         cnt += rev[c].size();       }     return d == cnt;   }   int ans[MAX_N];   void solve() {     cin >> n;     for (int i = (0), _b = (n); i < _b; ++i) cin >> f[i];     for (int i = (1), _b = (n); i < _b; ++i) {       int p;       cin >> p;       adj[p - 1].push_back(i);     }     dfs(0);     for (int i = 0; i < n; ++i) {       long long d = gcd(f[i], f[0]);       if (f[0] / d < MAX_N) {         rev[f[0] / d].push_back(i);       }     }     init();     for (int i = n; i > 0; --i)       if (check(i)) {         ans[i] += 1;         if (ans[i] >= mod) ans[i] -= mod;         for (int c : divisors[i])           if (c != i) {             ans[c] += ans[i];             if (ans[c] >= mod) ans[c] -= mod;           }       }     cout << ans[1] <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     const bool multiple_test = false;     int test = 1;     if (multiple_test) cin >> test;     for (int i = 0; i < test; ++i) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   struct lichao {     int l, r, A;     long long B;     lichao() : l(0), r(0), A(0), B(0x7fffffffffffffffLL) {}   };   const int SZ = 1 << 17;   vector<int> adj[100000];   vector<lichao> tree(2 * SZ);   int node_cnt, num[100000], A[100000], B[100000];   long long ans[100000];   int get_sign(long long a) { return a < 0 ? -1 : a > 0; }   void add_tree2(int A, long long B, int p, int s = -SZ, int e = SZ - 1) {     int m = (s + e) >> 1, &pA = tree[p].A;     long long &pB = tree[p].B;     long long ys = 1LL * A * s + B, ym = 1LL * A * m + B, ye = 1LL * A * e + B,               pys = 1LL * pA * s + pB, pym = 1LL * pA * m + pB,               pye = 1LL * pA * e + pB;     if (ym < pym) {       swap(A, pA);       swap(B, pB);       swap(ys, pys);       swap(ym, pym);       swap(ye, pye);     }     if (ys >= pys && ye >= pye) return;     if (get_sign(ys - pys) * get_sign(ym - pym) < 0 || ym == pym && ys < pys) {       if (tree[p].l == 0) tree[p].l = tree.size(), tree.push_back(lichao());       add_tree2(A, B, tree[p].l, s, m);     } else {       if (tree[p].r == 0) tree[p].r = tree.size(), tree.push_back(lichao());       add_tree2(A, B, tree[p].r, m + 1, e);     }   }   void add_tree(int n, int A, long long B) {     for (add_tree2(A, B, n += SZ); n >>= 1;) add_tree2(A, B, n);   }   long long get_min2(int x, int p, int s = -SZ, int e = SZ - 1) {     int m = (s + e) >> 1;     if (p == 0 || s == e) return 1LL * tree[p].A * x + tree[p].B;     return min(         1LL * tree[p].A * x + tree[p].B,         x <= m ? get_min2(x, tree[p].l, s, m) : get_min2(x, tree[p].r, m + 1, e));   }   long long get_min(int s, int e, int x) {     long long ret = 0x7fffffffffffffffLL;     for (s |= SZ, e |= SZ; s <= e; s >>= 1, e >>= 1) {       if (s & 1) ret = min(ret, get_min2(x, s++));       if (~e & 1) ret = min(ret, get_min2(x, e--));     }     return ret;   }   void dfs(int c) {     bool leaf = true;     num[c] = ++node_cnt;     for (auto n : adj[c])       if (num[n] == 0) {         leaf = false;         dfs(n);       }     ans[c] = (leaf ? 0 : get_min(num[c], node_cnt, A[c]));     add_tree(num[c], B[c], ans[c]);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ((void)0);     ((void)0);     ((void)0);     int N;     cin >> N;     for (int i = 0; i < N; i++) cin >> A[i];     for (int i = 0; i < N; i++) cin >> B[i];     for (int i = 1; i < N; i++) {       int a, b;       cin >> a >> b;       adj[--a].push_back(--b);       adj[b].push_back(a);     }     dfs(0);     for (int i = 0; i < N; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e5 + 9, lg = 30;   int a[inf * 3], n, table[lg][inf << 2];   int ans[inf], nxt[inf], sml[inf << 2];   void build() {     int i, j;     for (i = 1; i <= n + n; i++) table[0][i] = a[i];     for (j = 1; j < lg - 1; j++)       for (i = 1; i + (1 << (j - 1)) - 1 <= n + n; i++)         table[j][i] = min(table[j - 1][i], table[j - 1][i + (1 << (j - 1))]);   }   int query(int x, int y) {     int len, k;     len = y - x + 1;     k = log2(len);     return min(table[k][x], table[k][y + 1 - (1 << k)]);   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++)       cin >> a[i], a[i + n] = a[i], a[i + n + n] = a[i];     int mx = 0;     for (int i = n;; i++) {       if (mx > a[i]) break;       if (i == n + n + n) {         ans[n] = -1;         break;       }       ans[n]++;       mx = max(mx, (a[i] % 2 == 0 ? a[i] / 2 : a[i] / 2 + 1));     }     ans[n + n] = ans[n];     stack<int> st;     for (int i = n + n; i >= 1; i--) {       while (!st.empty() && a[st.top()] <= a[i]) st.pop();       if (st.empty())         nxt[i] = -1;       else         nxt[i] = st.top();       st.push(i);     }     build();     for (int i = 1; i <= n; i++) {       sml[i] = 1e9;       int val = (a[i] % 2 == 0 ? a[i] / 2 : a[i] / 2 + 1);       int l = i, r = min(n + n + 1, n + i + 1);       while (r - l > 1) {         int mid = (l + r) / 2;         if (query(i, mid) < val)           r = mid;         else           l = mid;       }       if (a[r] < val) sml[i] = r;     }     vector<pair<int, int> > v;     for (int i = 1; i <= n; i++) {       v.push_back(make_pair(a[i], i));     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     for (auto o : v) {       int i = o.second;       if (sml[i] == 1e9) {         if (nxt[i] == -1)           ans[i] = -1;         else           ans[i] = (ans[nxt[i]] != -1 ? ans[nxt[i]] + nxt[i] - i : -1);       } else {         if (nxt[i] == -1)           ans[i] = sml[i] - i;         else {           if (sml[i] < nxt[i])             ans[i] = sml[i] - i;           else             ans[i] = (ans[nxt[i]] != -1 ? ans[nxt[i]] + nxt[i] - i : -1);         }       }       ans[i + n] = ans[i];     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T abs(T a) {     return a < 0 ? -a : a;   }   template <typename T>   T sqr(T a) {     return a * a;   }   const int INF = (int)1e9;   const long double EPS = 1e-9;   const long double PI = 3.1415926535897932384626433832795;   int main() {     int n;     cin >> n;     cout << n <<    ;     for (int i = 1; i < n; i++) cout << i <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int p;   int pm(int x, int e) {     int res = 1;     int tmp = x;     while (e > 0) {       if (e & 1) res = ((long long)res * tmp) % p;       tmp = ((long long)tmp * tmp) % p;       e >>= 1;     }     return res;   }   bool prim() {     for (int i = 2; i * i <= p; ++i)       if (p % i == 0) return false;     return true;   }   vector<int> d;   void roz() {     int M = p - 1;     for (int i = 2; i * i < p; ++i) {       if (M % i == 0) d.push_back(M / i);     }   }   bool ok(int x) {     for (int i = 0; i < d.size(); ++i)       if (pm(x, d[i]) == 1) return false;     return true;   }   int gen() {     roz();     for (int i = 2; i < p; ++i) {       if (ok(i)) return i;     }   }   int main() {     scanf( %d , &p);     if (p == 1) {       printf( YES n1 n );     } else if (p == 2) {       printf( YES n1 n2 n );     } else if (p == 4) {       printf( YES n1 n3 n2 n4 n );     } else if (!prim()) {       printf( NO n );     } else {       int g = gen();       printf( YES n );       for (int i = 0; i < (p - 1) / 2; ++i) {         printf( %d n%d n , pm(g, p - 1 - 2 * i), pm(g, 1 + 2 * i));       }       printf( %d n , p);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   int main() {     long long n;     cin >> n;     string s;     cin >> s;     vector<int> v(26);     for (long long i = 0; i < n; i++) {       v[s[i] -  a ]++;     }     for (long long i = 0; i < 26; i++) {       while (v[i]--) {         char c = i +  a ;         cout << c;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   int k, n, m;   long long a[MAXN], g[MAXN], ii[MAXN], ty[MAXN];   vector<pair<long long, long long> > V[MAXN];   vector<pair<long long, pair<long long, long long> > > P;   bool Compare(pair<long long, pair<long long, long long> > A,                pair<long long, pair<long long, long long> > B) {     assert(A.second.first >= A.second.second);     assert(B.second.first >= B.second.second);     A.second.first -= A.second.second;     B.second.first -= B.second.second;     return A.second.first * B.second.second > A.second.second * B.second.first;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> k >> n >> m;     for (int i = 1; i <= k; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       int t, id, b;       cin >> t >> id >> b;       ty[i] = t;       if (t == 1) {         if (g[id] < b) {           g[id] = b;           ii[id] = i;         }       } else if (t == 2) {         V[id].emplace_back(b, i);       } else {         P.emplace_back(i, make_pair(b, 1));       }     }     for (int i = 1; i <= k; i++) {       if (a[i] < g[i]) {         V[i].emplace_back(g[i] - a[i], ii[i]);       }       sort(V[i].begin(), V[i].end(), greater<pair<long long, long long> >());       for (auto x : V[i]) {         P.emplace_back(x.second, make_pair(a[i] + x.first, a[i]));         a[i] += x.first;       }     }     sort(P.begin(), P.end(), Compare);     vector<pair<long long, long long> > L;     for (int i = 0; i < min(m, (int)P.size()); i++) {       L.emplace_back(ty[P[i].first], P[i].first);     }     sort(L.begin(), L.end());     cout << L.size() <<   n ;     for (auto x : L) {       cout << x.second <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > g[100005];   long long n, ans, ans2;   void dfs(long long u, long long p, long long cur) {     ans2 = max(ans2, cur);     for (auto e : g[u])       if (e.first != p) dfs(e.first, u, cur + e.second);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (long long i = 1; i <= n - 1; i++) {       long long a, b, w;       cin >> a >> b >> w;       g[a].push_back({b, w});       g[b].push_back({a, w});       ans += w * 2;     }     dfs(1, 0, 0);     cout << ans - ans2;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void rd(T &x) {     char ch;     x = 0;     bool fl = false;     while (!isdigit(ch = getchar())) (ch ==  - ) && (fl = true);     for (x = (ch ^  0 ); isdigit(ch = getchar()); x = x * 10 + (ch ^  0 ))       ;     (fl == true) && (x = -x);   }   template <class T>   inline void output(T x) {     if (x / 10) output(x / 10);     putchar(x % 10 +  0 );   }   template <class T>   inline void ot(T x) {     if (x < 0) putchar( - ), x = -x;     output(x);     putchar(   );   }   template <class T>   inline void prt(T a[], int st, int nd) {     for (register int i = st; i <= nd; ++i) ot(a[i]);     putchar(  n );   }   namespace Modulo {   const int mod = 998244353;   int ad(int x, int y) { return (x + y) >= mod ? x + y - mod : x + y; }   void inc(int &x, int y) { x = ad(x, y); }   int mul(int x, int y) { return (long long)x * y % mod; }   void inc2(int &x, int y) { x = mul(x, y); }   int qm(int x, int y = mod - 2) {     int ret = 1;     while (y) {       if (y & 1) ret = mul(x, ret);       x = mul(x, x);       y >>= 1;     }     return ret;   }   }  // namespace Modulo   namespace Miracle {   const int N = 300000 + 5;   const int inf = 0x3f3f3f3f;   int n, m;   int du[N];   int b[N][2];   vector<int> to[N];   int go[N];   int q[N], l, r, df;   void topo() {     l = 1, r = 0;     df = 0;     for (register int i = 1; i <= n; ++i) {       if (du[i] == 0) q[++r] = i;     }     while (l <= r) {       int x = q[l];       ++df;       int sz = r - l + 1;       ++l;       if (sz == 1) {         go[x] += n - df;       } else if (sz == 2) {         int b = q[l];         int lp = 0;         for (const auto &y : to[b]) {           if (du[y] == 1) {             lp = 1;             break;           }         }         if (!lp) {           go[x] += n - df - 1;         } else {           go[x] = -inf;         }       } else {         go[x] = -inf;       }       for (const auto &y : to[x]) {         --du[y];         if (du[y] == 0) {           q[++r] = y;         }       }     }   }   int main() {     rd(n);     rd(m);     for (register int i = 1; i <= m; ++i) {       rd(b[i][0]);       rd(b[i][1]);       to[b[i][0]].push_back(b[i][1]);       ++du[b[i][1]];     }     topo();     for (register int i = 1; i <= n; ++i) to[i].clear(), du[i] = 0;     for (register int i = 1; i <= m; ++i) {       to[b[i][1]].push_back(b[i][0]);       ++du[b[i][0]];     }     topo();     int ans = 0;     for (register int i = 1; i <= n; ++i) {       if (go[i] >= n - 2) ++ans;     }     ot(ans);     return 0;   }   }  // namespace Miracle   signed main() {     Miracle::main();     return 0;   }
#include <bits/stdc++.h>   long long f[2005][2005];   long long k[2005][2005];   long long C[4005][4005];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (register int i = 0; i <= n; ++i)       for (register int j = 0; j <= m; ++j) {         if (i == 0)           k[i][j] = 1;         else if (j == 0)           k[i][j] = 0;         else if (i > j)           k[i][j] = 0;         else           k[i][j] = (k[i - 1][j] + k[i][j - 1]) % 998244853;       }     C[0][0] = C[1][0] = C[1][1] = 1;     for (register int i = 2; i <= n + m; ++i) {       C[i][0] = 1;       for (register int j = 1; j <= i; ++j)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 998244853;     }     for (register int i = 0; i <= n; ++i) f[i][0] = i, f[0][i] = 0;     for (register int i = 1; i <= n; ++i)       for (register int j = 1; j <= m; ++j)         f[i][j] = ((f[i - 1][j] + C[i + j - 1][i - 1]) % 998244853 +                    (f[i][j - 1] - C[i + j - 1][i] + k[i][j - 1] + 998244853) %                        998244853) %                   998244853;     printf( %I64d , f[n][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 2000 + 4, Inf = 1e9 + 10;   int n, m, k;   char f[M][M];   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> k;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> f[i][j];     for (int i = 0; i < m; i++) {       int ans = 0;       for (int y = 2; y < n; y += 2)         if (f[y][i] ==  U ) ans++;       for (int x = i, y = 0; x >= 0 && y < n; y++, x--)         if (f[y][x] ==  R ) ans++;       for (int x = i, y = 0; x < m && y < n; y++, x++)         if (f[y][x] ==  L ) ans++;       cout << ans <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &n) {     n = 0;     T f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - ) f = -1, c = getchar();     while (isdigit(c)) n = n * 10 + c -  0 , c = getchar();     n *= f;   }   template <typename T>   void write(T n) {     if (n < 0) putchar( - ), n = -n;     if (n > 9) write(n / 10);     putchar(n % 10 +  0 );   }   int n, m, vis[105];   long long f[105][105], p[105][105];   struct node {     long long a, b;     int id;     friend bool operator<(node a, node b) { return a.b < b.b; }   } v[105];   int main() {     int T;     cin >> T;     while (T--) {       read(n), read(m);       for (int i = 1; i <= n; i++) {         read(v[i].a), read(v[i].b);         v[i].id = i;       }       sort(v + 1, v + n + 1);       memset(f, -0x3f, sizeof(f));       memset(p, 0, sizeof(p));       memset(vis, 0, sizeof(vis));       f[0][0] = 0;       for (int i = 1; i <= n; i++) {         for (int j = 0; j <= min(i, m); j++) {           f[i][j] = f[i - 1][j] + v[i].b * (m - 1);           if (j && f[i - 1][j - 1] + v[i].a + v[i].b * (j - 1) > f[i][j]) {             f[i][j] = f[i - 1][j - 1] + v[i].a + v[i].b * (j - 1);             p[i][j] = 1;           }         }       }       int t = m;       for (int i = n; i >= 1; i--) {         if (p[i][t]) {           vis[i] = 1;           t--;         }       }       printf( %d n , m + (n - m) * 2);       int cnt = 0, x;       for (int i = 1; i <= n; i++) {         if (!vis[i]) continue;         cnt++;         if (cnt == m)           x = v[i].id;         else           printf( %d  , v[i].id);       }       for (int i = 1; i <= n; i++) {         if (!vis[i]) printf( %d %d  , v[i].id, -v[i].id);       }       printf( %d n , x);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100050;   const int inf = 0x3f3f3f3f;   struct Edge {     int v, w;   };   vector<Edge> G[maxn];   bool vis[maxn];   vector<int> st;   int dep[maxn], f[maxn][20];   long long dis[maxn];   void dfs(int x, int par, long long sum) {     f[x][0] = par;     dep[x] = dep[par] + 1;     dis[x] = sum;     vis[x] = true;     for (int i = 1; f[x][i - 1]; ++i) f[x][i] = f[f[x][i - 1]][i - 1];     for (auto e : G[x]) {       int v = e.v;       if (v != par && vis[v]) {         st.push_back(v), st.push_back(x);       }       if (v != par && !vis[v]) dfs(v, x, sum + e.w);     }   }   int lca(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     int h = dep[x] - dep[y];     for (int i = 0; h; ++i) {       if (h & (1 << i)) {         x = f[x][i];         h ^= (1 << i);       }     }     if (x == y) return x;     for (int i = 17; i >= 0; --i) {       if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];     }     return f[x][0];   }   long long Dis(int x, int y) {     int z = lca(x, y);     return dis[x] + dis[y] - dis[z] * 2;   }   struct Dijkstra {     long long d[maxn];     struct node {       int x;       long long d;       node(int x = 0, long long d = 0) : x(x), d(d) {}       bool operator<(const node& t) const { return d > t.d; }     };     void run(int s) {       memset(d, 0x3f, sizeof d);       memset(vis, false, sizeof vis);       priority_queue<node> q;       q.push(node(s, 0)), d[s] = 0;       while (!q.empty()) {         node u = q.top();         q.pop();         if (vis[u.x]) continue;         vis[u.x] = true;         for (auto e : G[u.x]) {           int v = e.v;           if (!vis[v] && d[v] > u.d + e.w) {             d[v] = u.d + e.w;             q.push(node(v, d[v]));           }         }       }     }   } dij[50];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; ++i) {       int x, y, w;       scanf( %d%d%d , &x, &y, &w);       G[x].push_back({y, w});       G[y].push_back({x, w});     }     dfs(1, 0, 0);     sort(st.begin(), st.end());     int sz = unique(st.begin(), st.end()) - st.begin();     while (st.size() > sz) st.pop_back();     for (int i = 0; i < sz; ++i) {       dij[i].run(st[i]);     }     int q;     scanf( %d , &q);     while (q--) {       int u, v;       scanf( %d%d , &u, &v);       long long ans = Dis(u, v);       for (int i = 0; i < sz; ++i) ans = min(ans, dij[i].d[u] + dij[i].d[v]);       printf( %lld n , ans);     }     return 0;   }