Submission #230513

# Submission time Handle Problem Language Result Execution time Memory
230513 2020-05-10T09:35:41 Z VEGAnn Praktični (COCI18_prakticni) C++14
26 / 130
1000 ms 17912 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define pis pair<int,short>
#define ft first
#define sd second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int oo = 2e9;
const int N = 100100;
const int PW = 20;
vector<int> extra, vc;
vector<pii> g[N];
int U[N], V[N], C[N], pre[N], pr[N][PW], xr[N], tt = 0, tin[N], tout[N];
int XOR = -1, n, m;

bool cmp(int _x, int _y){
    return C[_x] < C[_y];
}

int get(int x) { return (pre[x] == x ? x : pre[x] = get(pre[x])); }

void dfs(int v, int p){
    tin[v] = tt++;

    pr[v][0] = p;

    for (int po = 1; po < PW; po++)
        pr[v][po] = pr[v][pr[v][po - 1]];

    for (pii u : g[v]){
        if (u.ft == p) continue;

        xr[u.ft] = (xr[v] ^ u.sd);

        dfs(u.ft, v);
    }

    tout[v] = tt++;
}

bool upper(int a, int b){
    return (tin[a] <= tin[b] && tout[a] >= tout[b]);
}

int lca(int a, int b){
    if (upper(a, b)) return a;
    if (upper(b, a)) return b;

    for (int po = PW - 1; po >= 0; po--)
        if (!upper(pr[a][po], b))
            a = pr[a][po];

    return pr[a][0];
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);

#ifdef _LOCAL
    freopen("in.txt","r",stdin);
#endif // _LOCAL

    cin >> n >> m;

    for (int i = 0; i < n; i++)
        pre[i] = i;

    for (int i = 0; i < m; i++){
        cin >> U[i] >> V[i] >> C[i];
        U[i]--; V[i]--;
    }

    for (int i = m - 1; i >= 0; i--){
        int x = get(U[i]), y = get(V[i]);

        if (x == y) {
            extra.PB(i);
        } else {
            pre[x] = y;
            g[U[i]].PB(MP(V[i], C[i]));
            g[V[i]].PB(MP(U[i], C[i]));
        }
    }

    dfs(0, 0);

    for (int nm : extra){
        int x = U[nm], y = V[nm];

        int cxr = (xr[x] ^ xr[y] ^ C[nm]);

        if (cxr != 0){
            if (XOR < 0)
                XOR = cxr;

            if (XOR != cxr){
                while (1) {}
            }

            vc.PB(nm);
        }
    }

    if (XOR < 0)
        cout << 0;
    else {
        cout << "1\n" << XOR << " " << sz(vc);

        for (int id : vc)
            cout << " " << id + 1;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 33 ms 7032 KB Output is correct
2 Correct 43 ms 8832 KB Output is correct
3 Correct 11 ms 3456 KB Output is correct
4 Correct 12 ms 4352 KB Output is correct
5 Correct 90 ms 17912 KB Output is correct
6 Correct 99 ms 17656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4224 KB Output is correct
2 Correct 18 ms 4480 KB Output is correct
3 Correct 26 ms 6400 KB Output is correct
4 Correct 27 ms 7040 KB Output is correct
5 Correct 72 ms 11640 KB Output is correct
6 Correct 39 ms 8056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 8320 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 13944 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 10488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 7284 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 14584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1084 ms 13432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 7040 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 15096 KB Time limit exceeded
2 Halted 0 ms 0 KB -