Submission #109959

# Submission time Handle Problem Language Result Execution time Memory
109959 2019-05-08T12:51:25 Z win11905 Praktični (COCI18_prakticni) C++11
130 / 130
173 ms 14912 KB
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author win11905
 */

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define long long long
#define pii pair<int, int>
#define iii tuple<int, int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

const int N = 1e5+5;

class prakticni {
private:
    int n, m;
    int s[N], t[N], w[N], d[N], cyc[N];
    vector<int> vec, g[N];
    bool check[N];
    void dfs(int u, int p) {
        check[u] = true;
        for(int x : g[u]) {
            int v = u ^ s[x] ^ t[x];
            if(v == p) continue;
            if(check[v]) vec.emplace_back(x), cyc[x] = d[v] ^ d[u] ^ w[x];
            else d[v] = d[u] ^ w[x], dfs(v, u);
        }
    }
public:
    void solve(istream& cin, ostream& cout) {
        cin >> n >> m;
        for(int i = 1; i <= m; ++i) {
            cin >> s[i] >> t[i] >> w[i];
            g[s[i]].emplace_back(i);
            g[t[i]].emplace_back(i);
        }
        dfs(1, 0);
        vector<pair<int, vector<int> > > ans;
        for(int i = 0; i < 30; ++i) {
            int val = 0;
            for(int v : vec) if(cyc[v] >> i & 1) val = cyc[v];
            if(!val) continue;
            vector<int> ret;
            for(int v : vec) if(cyc[v] >> i & 1) {
                ret.emplace_back(v);
                cyc[v] ^= val;
            }
            ans.emplace_back(val, ret);
        }
        cout << ans.size() << endl;
        for(auto z : ans) {
            cout << z.x << ' ' << z.y.size() << ' ';
            for(int v : z.y) cout << v << ' ';
            cout << endl;
        }
    }
};

class Solver {
public:
    void solve(std::istream& in, std::ostream& out) {
        prakticni *obj = new prakticni();
        obj->solve(in, out);
    }
};

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    Solver solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 46 ms 7040 KB Output is correct
2 Correct 41 ms 7160 KB Output is correct
3 Correct 12 ms 5376 KB Output is correct
4 Correct 11 ms 5376 KB Output is correct
5 Correct 93 ms 9976 KB Output is correct
6 Correct 95 ms 9308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 5888 KB Output is correct
2 Correct 23 ms 5888 KB Output is correct
3 Correct 25 ms 6272 KB Output is correct
4 Correct 29 ms 6392 KB Output is correct
5 Correct 81 ms 8912 KB Output is correct
6 Correct 65 ms 7384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 7988 KB Output is correct
2 Correct 86 ms 8472 KB Output is correct
3 Correct 6 ms 4736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 8824 KB Output is correct
2 Correct 133 ms 12784 KB Output is correct
3 Correct 8 ms 4864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 8184 KB Output is correct
2 Correct 83 ms 8312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 10468 KB Output is correct
2 Correct 49 ms 7032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 9212 KB Output is correct
2 Correct 112 ms 11888 KB Output is correct
3 Correct 82 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 12276 KB Output is correct
2 Correct 173 ms 14912 KB Output is correct
3 Correct 159 ms 13400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 6148 KB Output is correct
2 Correct 42 ms 6856 KB Output is correct
3 Correct 109 ms 10236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 9848 KB Output is correct
2 Correct 65 ms 7684 KB Output is correct
3 Correct 142 ms 12656 KB Output is correct