Submission #230497

# Submission time Handle Problem Language Result Execution time Memory
230497 2020-05-10T08:38:54 Z VEGAnn Praktični (COCI18_prakticni) C++14
0 / 130
117 ms 32504 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]--;

        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;

            assert(XOR == cxr);

            vc.PB(nm);
        }
    }

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

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

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 7928 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 4608 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 49 ms 17528 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 102 ms 29920 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 79 ms 22264 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 57 ms 15860 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 106 ms 31384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 108 ms 29308 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 14840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 117 ms 32504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -