Submission #231670

# Submission time Handle Problem Language Result Execution time Memory
231670 2020-05-14T10:47:14 Z Vimmer Praktični (COCI18_prakticni) C++14
130 / 130
137 ms 15220 KB
#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 100005
#define MOD ll(1e9 + 7)
#define block 500

using namespace std;

//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;

typedef short int si;

//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int pr[N], rk[N], a[N], b[N], c[N], basis[32], id[32], conv[32], sz, cnt[N];

vector <int> ans[32];

vector <pair <int, int> > g[N], vr;

void make(int x) {pr[x] = x; rk[x] = 1;}

vector <int> check;

int fnd(int x) {if (pr[x] != x) pr[x] = fnd(pr[x]); return pr[x];}

void link(int x, int y)
{
    if (rk[y] > rk[x]) swap(x, y);

    pr[y] = x;

    rk[x] += rk[y];
}

void dfs(int v, int p)
{
    for (auto it : g[v])
    {
        if (it.F == p) continue;

        cnt[it.F] = cnt[v] ^ it.S;

        dfs(it.F, v);
    }
}

void add_basis(int x)
{
    for (int i = 0; i < 32; i++)
      if ((1 << i) & x)
      {
          if (!basis[i])
          {
             basis[i] = x;

             id[i] = sz;

             conv[sz] = i;

             sz++;

             return;
          }

          x ^= basis[i];
      }
}

void add(pair <int, int> x)
{
    for (int i = 0; i < 32; i++)
      if ((1 << i) & x.S)
      {
          ans[id[i]].pb(x.F);

          x.S ^= basis[i];
      }
}
int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n, m;

    cin >> n >> m;

    for (int i = 1; i <= n; i++) make(i);

    for (int i = 1; i <= m; i++)
    {
        cin >> a[i] >> b[i] >> c[i];

        int x = fnd(a[i]), y = fnd(b[i]);

        if (x != y)
        {
            link(x, y);

            g[a[i]].pb({b[i], c[i]});

            g[b[i]].pb({a[i], c[i]});
        } else check.pb(i);
    }

    dfs(1, -1);

    for (auto it : check)
    {
        int t = cnt[a[it]] ^ cnt[b[it]] ^ c[it];

        if (!t) continue;

        vr.pb({it, t});

        add_basis(t);
    }

    if (!sz(vr)) {cout << 0 << endl; exit(0);}

    cout << sz << endl;

    for (auto it : vr) add(it);

    for (int i = 0; i < sz; i++)
    {
        cout << basis[conv[i]] << " " << sz(ans[i]) << " ";

        sort(ans[i].begin(), ans[i].end());

        for (auto it : ans[i]) cout << it << " ";

        cout << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 5880 KB Output is correct
2 Correct 36 ms 6520 KB Output is correct
3 Correct 11 ms 3456 KB Output is correct
4 Correct 12 ms 3584 KB Output is correct
5 Correct 81 ms 12152 KB Output is correct
6 Correct 75 ms 11768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 3968 KB Output is correct
2 Correct 17 ms 4096 KB Output is correct
3 Correct 22 ms 4736 KB Output is correct
4 Correct 25 ms 5248 KB Output is correct
5 Correct 62 ms 8824 KB Output is correct
6 Correct 37 ms 6520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 7288 KB Output is correct
2 Correct 64 ms 8952 KB Output is correct
3 Correct 6 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 9592 KB Output is correct
2 Correct 107 ms 13296 KB Output is correct
3 Correct 7 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 7928 KB Output is correct
2 Correct 64 ms 9592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 10112 KB Output is correct
2 Correct 40 ms 7160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 10720 KB Output is correct
2 Correct 99 ms 12288 KB Output is correct
3 Correct 62 ms 9208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 13428 KB Output is correct
2 Correct 137 ms 15220 KB Output is correct
3 Correct 119 ms 14828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 5496 KB Output is correct
2 Correct 34 ms 6136 KB Output is correct
3 Correct 81 ms 10876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 88 ms 11512 KB Output is correct
2 Correct 50 ms 7928 KB Output is correct
3 Correct 113 ms 13940 KB Output is correct