Submission #299279

# Submission time Handle Problem Language Result Execution time Memory
299279 2020-09-14T16:00:57 Z dolphingarlic None (balkan16_acrobat) C++14
100 / 100
362 ms 42960 KB
#include <bits/stdc++.h>
using namespace std;

int a[300001], b[300001], cmp[600001];
bool cnt[300001], visited[300001];
vector<pair<int, int>> graph[300001];
vector<array<int, 3>> ans;

int find(int A) {
    while (A != cmp[A]) A = cmp[A], cmp[A] = cmp[cmp[A]];
    return A;
}

void onion(int A, int B) { cmp[find(A)] = find(B); }

bool dfs(int node) {
    visited[node] = true;
    for (pair<int, int> i : graph[node]) {
        if (!visited[i.first] && dfs(i.first)) {
            ans.push_back({1, a[i.second], b[i.second]});
            swap(a[i.second], b[i.second]);
            cnt[node] ^= 1;
        }
    }
    return cnt[node];
}

int main() {
    iostream::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        cnt[a[i]] ^= 1;
        graph[a[i]].push_back({b[i], i});
        graph[b[i]].push_back({a[i], i});
    }
    for (int i = 1; i <= n; i++) {
        if (!visited[i] && dfs(i)) return cout << -1, 0;
    }

    memset(cnt, 0, sizeof cnt);
    iota(cmp + 1, cmp + 2 * n + 1, 1);
    for (int i = 0; i < m; i++) {
        cnt[b[i]] ^= 1;
        onion(a[i] + n, b[i]);
    }
    for (int i = 1; i <= n; i++) if (find(1) != find(i)) {
        ans.push_back({2, 1, i});
        cnt[1] ^= 1;
        cnt[i] ^= 1;
        onion(1, i);
    }
    vector<int> odd;
    for (int i = 1; i <= n; i++) if (cnt[i]) odd.push_back(i);
    for (int i = 0; i < odd.size(); i += 2) ans.push_back({2, odd[i], odd[i + 1]});

    cout << ans.size() << '\n';
    for (array<int, 3> i : ans) {
        cout << i[0] << ' ' << i[1] << ' ' << i[2] << '\n';
    }
    return 0;
}

Compilation message

main.cpp: In function 'int main()':
main.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for (int i = 0; i < odd.size(); i += 2) ans.push_back({2, odd[i], odd[i + 1]});
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7680 KB Output is correct
2 Correct 6 ms 7680 KB Output is correct
3 Correct 6 ms 7680 KB Output is correct
4 Correct 6 ms 7680 KB Output is correct
5 Correct 5 ms 7680 KB Output is correct
6 Correct 5 ms 7680 KB Output is correct
7 Correct 6 ms 7680 KB Output is correct
8 Correct 5 ms 7680 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 6 ms 7680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 7680 KB Output is correct
2 Correct 5 ms 7680 KB Output is correct
3 Correct 6 ms 7680 KB Output is correct
4 Correct 6 ms 7680 KB Output is correct
5 Correct 6 ms 7680 KB Output is correct
6 Correct 6 ms 7680 KB Output is correct
7 Correct 6 ms 7680 KB Output is correct
8 Correct 6 ms 7680 KB Output is correct
9 Correct 6 ms 7424 KB Output is correct
10 Correct 5 ms 7680 KB Output is correct
11 Correct 5 ms 7552 KB Output is correct
12 Correct 6 ms 7808 KB Output is correct
13 Correct 6 ms 7808 KB Output is correct
14 Correct 5 ms 7680 KB Output is correct
15 Correct 6 ms 7808 KB Output is correct
16 Correct 6 ms 7808 KB Output is correct
17 Correct 6 ms 7680 KB Output is correct
18 Correct 6 ms 7808 KB Output is correct
19 Correct 6 ms 7936 KB Output is correct
20 Correct 6 ms 7680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 7680 KB Output is correct
2 Correct 5 ms 7680 KB Output is correct
3 Correct 6 ms 7680 KB Output is correct
4 Correct 6 ms 7680 KB Output is correct
5 Correct 6 ms 7680 KB Output is correct
6 Correct 7 ms 7680 KB Output is correct
7 Correct 8 ms 7680 KB Output is correct
8 Correct 6 ms 7680 KB Output is correct
9 Correct 5 ms 7424 KB Output is correct
10 Correct 6 ms 7680 KB Output is correct
11 Correct 6 ms 7424 KB Output is correct
12 Correct 6 ms 7808 KB Output is correct
13 Correct 6 ms 7936 KB Output is correct
14 Correct 7 ms 7808 KB Output is correct
15 Correct 8 ms 7808 KB Output is correct
16 Correct 6 ms 7808 KB Output is correct
17 Correct 6 ms 7680 KB Output is correct
18 Correct 6 ms 7808 KB Output is correct
19 Correct 6 ms 7936 KB Output is correct
20 Correct 6 ms 7680 KB Output is correct
21 Correct 326 ms 28912 KB Output is correct
22 Correct 362 ms 39556 KB Output is correct
23 Correct 161 ms 26712 KB Output is correct
24 Correct 52 ms 16632 KB Output is correct
25 Correct 63 ms 18168 KB Output is correct
26 Correct 221 ms 31976 KB Output is correct
27 Correct 95 ms 20984 KB Output is correct
28 Correct 81 ms 21240 KB Output is correct
29 Correct 233 ms 42960 KB Output is correct
30 Correct 212 ms 38224 KB Output is correct
31 Correct 74 ms 16888 KB Output is correct
32 Correct 250 ms 39260 KB Output is correct
33 Correct 6 ms 7808 KB Output is correct
34 Correct 6 ms 7808 KB Output is correct
35 Correct 291 ms 28784 KB Output is correct
36 Correct 73 ms 17016 KB Output is correct
37 Correct 6 ms 7808 KB Output is correct
38 Correct 6 ms 7936 KB Output is correct