malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long f[200][200], a[200], x[200], y[200], d;   int n;   long long dist(int i, int j) { return abs(x[i] - x[j]) + abs(y[i] - y[j]); }   int main() {     cin >> n >> d;     for (int i = 2; i <= n - 1; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];     memset(f, 61, sizeof(f));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         if (i != j) f[i][j] = dist(i, j) * d - a[i];     for (int i = 1; i <= n; i++) f[i][i] = 0;     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) f[i][j] = min(f[i][j], f[i][k] + f[k][j]);     if (f[1][n] <= 0)       cout << 0;     else       cout << f[1][n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 4e5 + 10;   int sum[mx];   int x[mx];   int n, m;   void add(int x) {     while (x <= 2 * n + 1) {       sum[x]++;       x += x & (-x);     }   }   int query(int x) {     int ans = 0;     while (x) {       ans += sum[x];       x -= x & (-x);     }     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &x[i]);     int cnt = n + 1;     long long int a = 0, b = 0;     add(cnt);     for (int i = 1; i <= n; i++) {       if (x[i] < m)         cnt--;       else         cnt++;       a += query(cnt - 1);       add(cnt);     }     cnt = n + 1;     memset(sum, 0, sizeof(sum));     add(cnt);     for (int i = 1; i <= n; i++) {       if (x[i] <= m)         cnt--;       else         cnt++;       b += query(cnt - 1);       add(cnt);     }     printf( %I64d n , a - b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void topsort(long long int s, vector<vector<long long int>> &graph,                vector<long long int> &vis, vector<long long int> &ans) {     vis[s] = 1;     for (long long int i = 0; i < graph[s].size(); i++) {       if (vis[graph[s][i]] == 0) topsort(graph[s][i], graph, vis, ans);     }     ans.push_back(s);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     vector<long long int> v;     for (long long int i = 0; i < n; i++) {       long long int num;       cin >> num;       v.push_back(num);     }     vector<vector<long long int>> graph(n);     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < n; j++) {         if ((v[i] % 3 == 0 && v[j] == v[i] / 3) || v[j] == v[i] * 2)           graph[i].push_back(j);       }     }     vector<long long int> ans;     vector<long long int> vis(n, 0);     for (long long int i = 0; i < n; i++) {       if (vis[i] == 0) topsort(i, graph, vis, ans);     }     reverse(ans.begin(), ans.end());     for (long long int i = 0; i < ans.size(); i++) {       cout << v[ans[i]] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 11;   set<int> ans;   int n, m, len;   int a[N], b[N], c[N], p[N];   inline void manacher() {     c[0] = -2;     for (register int i = 0; i <= n + n - 2; ++i) c[++len] = b[i], c[++len] = -1;     c[len + 1] = -3;     int id = 0, mx = 0;     for (register int i = 1; i <= len; ++i) {       if (mx > i)         p[i] = min(mx - i, p[id + id - i]);       else         p[i] = 1;       while (c[i + p[i]] == c[i - p[i]]) ++p[i];       if (p[i] + i > mx) id = i, mx = i + p[i];     }   }   int main() {     scanf( %d%d , &n, &m);     for (register int i = 0; i <= n - 1; ++i) scanf( %d , a + i);     sort(a, a + n);     for (register int i = 1; i <= n; ++i)       b[i - 1] = (a[i % n] - a[i - 1] + m) % m;     for (register int i = 0; i <= n - 1; ++i) b[i + n] = b[i];     manacher();     for (int i = 2; i <= len; i += 2)       if (p[i] / 2 >= n / 2 &&           (a[(i / 2 - 1 + n) % n] + a[(i / 2 + 1) % n]) % m ==               a[i / 2 % n] * 2 % m)         ans.insert(a[i / 2 % n] * 2 % m);     if (n % 2 == 0) {       for (int i = 1; i <= len; i += 2)         if (p[i] >= n) ans.insert((a[i / 2 % n] + a[(i / 2 + 1) % n]) % m);     }     printf( %d n , ans.size());     for (auto v : ans) printf( %d  , v);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000000 + 1;   int a[MAXN], parent[MAXN], rnk[MAXN], p[10 * MAXN];   int n;   void make_set(int v) {     parent[v] = v;     rnk[v] = 0;   }   int find_set(int v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(int u, int v) {     u = find_set(u);     v = find_set(v);     if (u != v) {       if (rnk[u] < rnk[v]) swap(u, v);       parent[v] = u;       if (rnk[u] == rnk[v]) ++rnk[u];     }   }   int gcd(int x, int y) { return x ? gcd(y % x, x) : y; }   bool check(int m[3]) {     return gcd(m[0], m[1]) == 1 && gcd(m[1], m[2]) == 1 && gcd(m[0], m[2]) == 1;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       make_set(i);       p[a[i]] = i + 1;     }     sort(a, a + n);     for (int i = 2; i * i <= 2 * a[n - 1]; ++i)       for (int j = 1; j < i; ++j) {         int t[3] = {i * i - j * j, 2 * i * j, i * i + j * j};         if (!check(t)) continue;         int pos[3];         for (int k = 0; k < 3; ++k)           if (t[k] <= a[n - 1]) pos[k] = p[t[k]];         if (t[0] <= a[n - 1] && t[1] <= a[n - 1] && pos[0] && pos[1])           union_sets(pos[0] - 1, pos[1] - 1);         if (t[1] <= a[n - 1] && t[2] <= a[n - 1] && pos[1] && pos[2])           union_sets(pos[1] - 1, pos[2] - 1);         if (t[0] <= a[n - 1] && t[2] <= a[n - 1] && pos[0] && pos[2])           union_sets(pos[0] - 1, pos[2] - 1);       }     set<int> f;     for (int i = 0; i < n; ++i) f.insert(find_set(i));     printf( %d , f.size());     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> edges;   vector<int> g[300001];   int police[300001];   int nearest[300001];   int stat[300001];   void dfs1(int beta, int baap) {     int mini = (police[beta] ? 0 : (int)1e9), minpos = (police[beta] ? beta : -1);     for (int i = 0; i < g[beta].size(); i++) {       int pota = g[beta][i];       if (pota == baap) continue;       dfs1(pota, beta);       if (mini > 1 + nearest[pota]) {         mini = 1 + nearest[pota];         minpos = stat[pota];       }     }     nearest[beta] = mini;     stat[beta] = minpos;   }   void dfs2(int beta, int baap) {     int up = (baap == -1 ? (int)1e9 : 1 + nearest[baap]);     if (up < nearest[beta]) {       nearest[beta] = up;       stat[beta] = stat[baap];     }     for (int i = 0; i < g[beta].size(); i++) {       int pota = g[beta][i];       if (pota == baap) continue;       dfs2(pota, beta);     }   }   int main() {     int n, k, d;     scanf( %d %d %d , &n, &k, &d);     for (int i = 0; i < k; i++) {       int x;       scanf( %d , &x);       police[x] = 1;     }     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d %d , &x, &y);       g[x].push_back(y);       g[y].push_back(x);       edges.push_back(make_pair(x, y));     }     dfs1(1, -1);     dfs2(1, -1);     vector<int> ans;     for (int i = 0; i < n - 1; i++) {       int u = edges[i].first, v = edges[i].second;       if (stat[u] != stat[v]) ans.push_back(i + 1);     }     printf( %d n , (int)ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %d  , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void _split(vector<string>& vc, const string& str, char ch) {     string temp;     for (int i = 0; i <= str.size(); i++)       if (i == str.size() || str[i] == ch) {         vc.emplace_back(temp);         temp =   ;       } else {         temp += str[i];       }   }   void _output(vector<string>::iterator _) {     cerr <<   n ;     cerr.flush();   }   template <typename T, typename... Args>   void _output(vector<string>::iterator it, T val, Args... args) {     cerr << *it <<   =   << val <<      ;     _output(++it, args...);   }   const size_t MAX_N = 1000 + 5;   int n, a[MAX_N], b[MAX_N], cnt[MAX_N];   bool used[MAX_N];   inline bool check() {     int cnt = 0;     memset(used, 0, sizeof used);     for (int i = 0; i < n; i++)       if (a[i] != b[i]) cnt++;     if (cnt != 1) return false;     for (int i = 0; i < n; i++) used[a[i]] = true;     for (int i = 1; i <= n; i++)       if (!used[i]) return false;     return true;   }   int main() {     int diff_cnt = 0, i, j, k;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , a + i);     for (i = 0; i < n; i++) scanf( %d , b + i);     for (i = 0; i < n; i++) diff_cnt += a[i] != b[i];     if (!diff_cnt) {       for (i = 0; i < n; i++) cnt[a[i]]++;       for (i = 0; i < n; i++) cnt[b[i]]++;       for (j = 1; j <= n; j++)         if (cnt[j] == 4) break;       for (k = 1; k <= n; k++)         if (cnt[k] == 0) break;       for (i = 0; i < n; i++)         if (a[i] == j) {           printf( %d  , k);           break;         } else {           printf( %d  , a[i]);         }       for (; i < n; i++) printf( %d  , a[i]);     } else if (diff_cnt == 1) {       for (i = 0; i < n; i++)         if (a[i] == b[i]) cnt[a[i]]++;       for (j = 1; j <= n; j++)         if (!cnt[j]) break;       for (i = 0; i < n; i++)         if (a[i] == b[i])           printf( %d  , a[i]);         else           printf( %d  , j);     } else {       vector<int> lft, pos;       for (i = 0; i < n; i++)         if (a[i] == b[i])           cnt[a[i]]++;         else           pos.emplace_back(i);       for (i = 1; i <= n; i++)         if (!cnt[i]) lft.emplace_back(i);       for (int x : pos)         for (int l : lft)           if (l != a[x]) {             int t = a[x];             a[x] = l;             if (check()) {               for (i = 0; i < n; i++) printf( %d  , a[i]);               return 0;             }             a[x] = t;           }     }   }
#include <bits/stdc++.h>   using namespace std;   pair<int, long long> solve(long long n) {     if (!n) return {0, 0};     long long a = 1;     while ((a + 1) * (a + 1) * (a + 1) <= n) a++;     pair<int, long long> r1 = solve(n - a * a * a),                          r2 =                              solve((a * a * a) - 1 - (a - 1) * (a - 1) * (a - 1));     if (r1.first > r2.first) return {1 + r1.first, r1.second + a * a * a};     if (r1.first < r2.first)       return {1 + r2.first, r2.second + (a - 1) * (a - 1) * (a - 1)};     return {1 + r1.first,             max(a * a * a + r1.second, (a - 1) * (a - 1) * (a - 1) + r2.second)};   }   int main() {     long long n;     scanf( %lld , &n);     pair<int, long long> r = solve(n);     printf( %d %lld n , r.first, r.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unordered_map<int, int> X, pre;   unordered_map<int, int>::iterator it;   int Find(int u) {     it = pre.find(u);     if (it == pre.end()) {       X[u] = 0;       return u;     }     int v = it->second;     int tmp = Find(v);     X[u] ^= X[v];     return pre[u] = tmp;   }   bool join(int a, int b, int x) {     int c = Find(a), d = Find(b);     if (c == d) return false;     pre[d] = c;     X[d] = X[a] ^ X[b] ^ x;     return true;   }   int main() {     int q, last = 0;     scanf( %d , &q);     while (q--) {       int tp, a, b;       scanf( %d%d%d , &tp, &a, &b);       a ^= last;       b ^= last;       if (a > b) swap(a, b);       b++;       if (tp == 1) {         int x;         scanf( %d , &x);         join(a, b, x ^ last);       } else {         if (Find(a) != Find(b))           last = -1;         else           last = X[a] ^ X[b];         printf( %d n , last);         last = abs(last);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[1000];     int m = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       m = max(m, a[i]);     }     for (int i = 1; i <= m; i++) {       for (int j = 0; j < n; j++) a[j]--;       bool f[1000];       f[0] = (a[0] > 0);       for (int i = 1; i < n; i++)         f[i] = (a[i] > 0 && (f[i - 1] || (i > 1 && f[i - 2])));       if (!f[n - 1]) {         cout << i;         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int tc;     cin >> tc;     while (tc--) {       int test = 0;       int t[1005];       int n, x, nb1 = 0, nb2 = 0, i;       cin >> n >> x;       for (i = 0; i < n; i++) {         cin >> t[i];         if (t[i] % 2 == 0)           nb1++;         else           nb2++;       }       if (nb1 > 0 && x - nb1 > 0 && nb2 >= x - nb1 && (x - nb1) % 2 != 0)         cout <<  Yes  << endl;       else if (nb1 > 0 && x - nb1 + 1 > 0 && nb2 >= x - nb1 + 1 &&                (x - nb1 + 1) % 2 != 0)         cout <<  Yes  << endl;       else if (nb1 > 0 && x - nb1 <= 0 && nb2 >= 1)         cout <<  Yes  << endl;       else if (nb1 == 0 && x % 2 != 0 && nb2 >= x)         cout <<  Yes  << endl;       else         cout <<  No  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   char a[55][55];   int n, m, x;   int dist(int p, int q, int r, int s) {     return (p - r) * (p - r) + (q - s) * (q - s);   }   int ok[128] = {}, appear[128] = {};   char s[1000000];   int main(void) {     scanf( %d%d%d , &n, &m, &x);     for (int i = 0; i < n; i++) scanf( %s , a[i]);     int S = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (a[i][j] ==  S ) {           S = 1;           for (int u = 0; u < n; u++)             for (int v = 0; v < m; v++)               if (dist(i, j, u, v) <= x * x) {                 ok[(int)a[u][v]] = 1;               }         } else           appear[(int)a[i][j]] = 1;     scanf( %d , &n);     scanf( %s , s);     int ans = 0, f = 0;     for (int i = 0; s[i]; i++)       if (s[i] >=  A  && s[i] <=  Z ) {         if (!S || !appear[s[i] + 32]) f = 1;         ans += !ok[s[i] + 32];       } else if (!appear[(int)s[i]])         f = 1;     if (f) ans = -1;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const long long ooo = 9223372036854775807ll;   const int _cnt = 1000 * 1000 + 7;   const int _p = 1000 * 1000 * 1000 + 7;   const int N = 300005;   const double PI = acos(-1.0);   const double eps = 1e-9;   int o(int x) { return x % _p; }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   void file_put() {     freopen( filename.in ,  r , stdin);     freopen( filename.out ,  w , stdout);   }   int n, a[N], L, t;   long long ret = 0;   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]), ret += a[i];     for (int i = (1); i <= (n); ++i) {       if (a[i] >= 2)         t = ((a[i] >> 1) < (L) ? (a[i] >> 1) : (L)), a[i] -= t << 1, L -= t;       a[i] %= 3, L += a[i];     }     printf( %lld n , (ret - L) / 3);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> gr;   vector<long long> c;   vector<int> parent;   vector<int> size;   vector<char> used;   void make_set(int v) {     parent[v] = v;     size[v] = 1;   }   int find_set(int v) {     if (v == parent[v]) return v;     return parent[v] = find_set(parent[v]);   }   void union_sets(int a, int b) {     a = find_set(a);     b = find_set(b);     if (a != b) {       if (size[a] < size[b]) swap(a, b);       parent[b] = a;       size[a] += size[b];     }   }   long long binpow(long long a, int n) {     long long res = 1;     while (n) {       if (n & 1) {         res *= a;         res %= 1000000007;       }       a *= a;       a %= 1000000007;       n >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     long long k;     cin >> n >> m >> k;     c.resize(n);     for (int i = 0; i < n; ++i) cin >> c[i];     vector<map<long long, int>> adjacent(n);     vector<pair<int, int>> edges(m);     parent.resize(m);     size.resize(m);     used.resize(m, 0);     for (int i = 0; i < m; ++i) {       make_set(i);       int a, b;       cin >> a >> b;       --a, --b;       edges[i].first = a;       edges[i].second = b;     }     for (int i = 0; i < m; ++i) {       int from = edges[i].first;       int to = edges[i].second;       long long xr = c[to] ^ c[from];       {         auto found = adjacent[from].find(xr);         if (found != adjacent[from].end()) {           union_sets(i, found->second);         } else {           adjacent[from][xr] = i;         }       }       {         auto found = adjacent[to].find(xr);         if (found != adjacent[to].end()) {           union_sets(i, found->second);         } else {           adjacent[to][xr] = i;         }       }     }     vector<set<int>> subgraphs(m);     for (int i = 0; i < m; ++i) {       int comp = find_set(i);       int from = edges[i].first;       int to = edges[i].second;       subgraphs[comp].insert(from);       subgraphs[comp].insert(to);     }     long long ans = binpow(2, n + k);     map<long long, long long> q;     for (int i = 0; i < m; ++i) {       int comp = find_set(i);       if (!used[comp]) {         used[comp] = 1;         int from = edges[i].first;         int to = edges[i].second;         long long xr = c[to] ^ c[from];         q[xr] += subgraphs[comp].size() - 1;       }     }     for (auto it = q.begin(); it != q.end(); ++it) {       ans -= binpow(2, n);       if (ans < 0) ans += 1000000007;       ans += binpow(2, n - it->second);       ans %= 1000000007;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[100005], b[100005];   int l[100005], r[100005];   using pii = pair<int, int>;   using ppi = pair<pii, int>;   int tr[100005 * 2];   int get(int k) {     int res = 0;     for (; k; k -= k & -k) res += tr[k];     return res;   }   void update(int k) {     for (; k <= m; k += k & -k) tr[k]++;   }   void calc(int *g, int *gg) {     vector<ppi> V;     for (int i = 1; i <= n; i++)       V.push_back(ppi(pii(min(a[i], b[i]), max(a[i], b[i])), i));     sort(V.begin(), V.end(), [](const ppi &x, const ppi &y) {       return x.first.second < y.first.second;     });     int cnt = 0;     memset(tr, 0, sizeof tr);     for (auto x : V) {       g[x.second] = cnt - get(x.first.first);       update(x.first.first);       cnt++;     }     reverse(V.begin(), V.end());     memset(tr, 0, sizeof tr);     cnt = 0;     for (auto x : V) {       gg[x.second] = cnt - get(x.first.second) + get(x.first.first);       update(x.first.first);       cnt++;     }     memset(tr, 0, sizeof tr);     for (auto x : V) update(x.first.second);     for (auto x : V) gg[x.second] += get(x.first.first);     return;   }   int main() {     scanf( %d , &n);     m = 2 * n;     for (int i = 1; i <= n; i++) scanf( %d %d , &a[i], &b[i]);     calc(l, r);     long long ans = 0;     for (int i = 1; i <= n; i++) {       int t = n - 1 - l[i] - r[i];       ans += 1ll * t * (l[i] + r[i]);     }     ans >>= 1;     for (int i = 1; i <= n; i++) ans += 1ll * l[i] * r[i];     ans = 1ll * n * (n - 1) * (n - 2) / 6 - ans;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %i , &n);     vector<pair<int, int>> tree(n);     for (int x = 0; x < n; x++) {       scanf( %i%i , &tree[x].first, &tree[x].second);     }     sort(tree.begin(), tree.end());     int current_day = 0;     for (int i = 0; i < n; i++) {       current_day =           (tree[i].second < tree[i].first && tree[i].second >= current_day)               ? tree[i].second               : tree[i].first;     }     printf( %i n , current_day);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   vector<string> ss;   double check(const string& x) {     double res = 0;     if (x.size() < 3) {       for (char c : x) {         res = res * 10 + (int)c -  0 ;       }       return res;     }     if (x[x.size() - 3] ==  . ) {       for (int i = 0; i < x.size() - 3; ++i) {         if (x[i] ==  . ) continue;         res = res * 10 + (int)x[i] -  0 ;       }       res += ((int)x[x.size() - 2] -  0 ) / 10.0;       res += ((int)x[x.size() - 1] -  0 ) / 100.0;       return res;     } else {       for (int i = 0; i < x.size(); ++i) {         if (x[i] ==  . ) continue;         res = res * 10 + (int)x[i] -  0 ;       }       return res;     }   }   int main(int argc, const char* argv[]) {     cin >> s;     for (int i = 0; i < s.size(); ++i) {       if (s[i] >=  0  && s[i] <=  9 ) {         for (int j = i; j < s.size(); ++j) {           if (j == s.size() - 1) {             ss.emplace_back(s.substr(i, j - i + 1));             i = j;             continue;           }           if (s[j] >=  a  && s[j] <=  z ) {             ss.emplace_back(s.substr(i, j - i));             i = j - 1;             break;           }         }       }     }     double ans = 0;     for (auto& x : ss) {       ans += check(x);     }     char sans[5000];     sprintf(sans,  %.2f , ans);     int len = (int)strlen(sans);     int cnt = (len - 3) % 3;     if (cnt == 0) cnt = 3;     for (int i = 0; i < cnt; ++i) putchar(sans[i]);     for (int i = cnt; i < len - 3; i += 3) {       if (cnt) putchar( . );       putchar(sans[i]);       putchar(sans[i + 1]);       putchar(sans[i + 2]);     }     if (sans[len - 1] !=  0  || sans[len - 2] !=  0 ) {       putchar( . );       putchar(sans[len - 2]);       putchar(sans[len - 1]);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000000000 )   using namespace std;   int n;   double a[500001], b[500001], p, q;   string st;   double calc(double y1) {     double y2 = 1.;     for (int i = 0; i < n; i++) {       y2 = min(y2, (1. - (a[i] * y1)) / b[i]);     }     double ret = p * y1 + q * y2;     return ret;   }   int main() {     cin >> n >> p >> q;     double maxi = 0;     for (int i = 0; i < n; i++) {       cin >> a[i] >> b[i];       maxi = max(a[i], maxi);     }     double l = 0, r = 1. / maxi;     for (int i = 0; i < 100; i++) {       double m1 = (fabs(l - r)) / 3;       double x1 = calc(l + m1), x2 = calc(r - m1);       if (x1 >= x2)         r = r - m1;       else         l = l + m1;     }     printf( %.10lf n , calc(l));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 5;   vector<vector<int> > col;   vector<vector<int> > adj;   int color[N];   void dfs(int v, int p) {     set<int> st;     int toapply = 1;     for (int i = 0; i < col[v].size(); i++) {       int c = col[v][i];       if (color[c] != -1) st.insert(color[c]);     }     for (int i = 0; i < col[v].size(); i++) {       int c = col[v][i];       if (color[c] != -1) continue;       while (st.find(toapply) != st.end()) toapply++;       color[c] = toapply;       toapply++;     }     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (u == p) continue;       dfs(u, v);     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     col.resize(n + 5);     adj.resize(n + 5);     memset(color, -1, sizeof(color));     int mx = 1;     for (int i = 1; i <= n; i++) {       int s;       scanf( %d , &s);       mx = max(mx, s);       while (s--) {         int t;         scanf( %d , &t);         col[i].push_back(t);       }     }     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, -1);     printf( %d n , mx);     for (int i = 1; i <= m; i++)       if (color[i] == -1) color[i] = 1;     for (int i = 1; i <= m; i++) printf( %d  , color[i]);     printf(  n );     return 0;   }