Submission #301475

# Submission time Handle Problem Language Result Execution time Memory
301475 2020-09-18T01:52:21 Z 12tqian Connecting Supertrees (IOI20_supertrees) C++14
96 / 100
263 ms 22264 KB
#ifdef LOCAL
#else
#include "supertrees.h"
#endif
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }
#ifdef LOCAL
bool build(vector<vector<int>> p) {
    return true;
}
#else
#endif
int construct(vector<vector<int>> p) {
    int n = p.size();
    vector<vector<int>> res(n, vector<int>(n, 0));
    vector<bool> vis(n);
    auto ae = [&](int u, int v) {
        res[u][v] = 1;
        res[v][u] = 1;
    };
    auto make_cycle = [&](vector<int>& v) {
        for (int i = 0; i < v.size(); i++) {
            ae(v[i], v[(i + 1) % v.size()]);
        }
    };
    auto make_triple = [&](vector<int>& v) {
        make_cycle(v);
        ae(v[0], v[1]);
    };
    auto make_chain = [&](vector<int>& v) {
        for (int i = 0; i < v.size() - 1; i++) {
            ae(v[i], v[i + 1]);
        }
    };
    for (int i = 0; i < n; i++) {
        if (vis[i]) continue;
        vector<int> comp;
        function<void(int)> dfs_comp = [&](int src) {
            vis[src] = true;
            comp.push_back(src);
            for (int nxt = 0; nxt < n; nxt++) {
                if (p[src][nxt] == 0 || vis[nxt]) continue;
                dfs_comp(nxt);
            }
        };
        dfs_comp(i);
        int sz = comp.size();
        vector<int> overall(4);
        vector<int> one;
        vector<int> other;
        for (int x: comp) {
            vector<int> cnt(4);
            for (int y: comp) {
                if (x == y) continue;
                cnt[p[x][y]]++;
                overall[p[x][y]]++;
            }
            if (cnt[0]) {
                return 0;
            }
            if (cnt[1] == 0) {
                other.push_back(x);
            } else {
                one.push_back(x);
            }
        }
        if (overall[0] || overall[2] && overall[3]) {
            return 0;
        }
        if (overall[2] == 0 && overall[3] == 0) {
            vector<int> big;
            for (int x: one) big.push_back(x);
            for (int x: other) big.push_back(x);
            make_chain(big);
            continue;
        }
        vector<vector<int>> chains;
        for (int x: one) {
            bool done = false;
            for(auto& y: chains) {
                bool ok = false;
                for (int z: y) {
                    if (p[x][z] != 1) {
                        ok = true;
                        break;
                    }
                }
                if (ok == false) {
                    y.push_back(x);
                    done = true;
                    break;
                }
            }
            if (done == false) {
                chains.push_back(vector<int>(0));
                chains.back().push_back(x);
            }
        }
        for (auto& c: chains) {
            for (int x: c) {
                for (int y: c) {
                    if (p[x][y] != 1) {
                        return 0;
                    }
                }
            }
        }
        for (int j = 0; j < chains.size(); j++) {
            for (int k = j + 1; k < chains.size(); k++) {
                for (int x: chains[j]) {
                    for (int y: chains[k]) {
                        if (p[x][y] == 1) {
                            return 0;
                        }
                    }
                }
            }
        }
        int cycle = chains.size() + other.size();
        if (overall[2]) {
            if (cycle < 3) {
                return 0;
            }
            for (auto x: chains) {
                other.push_back(x[0]);
                make_chain(x);
            }
            make_cycle(other);
        } else if (overall[3]) {
            if (cycle < 4) {
                return 0;
            }
            for (auto x: chains) {
                other.push_back(x[0]);
                make_chain(other);
            }
            make_triple(other);
        } else {
            vector<int> big;
            for (int x: one) big.push_back(x);
            for (int x: other) big.push_back(x);
            make_chain(big);
        }
    }
    build(res);
    return 1;
}
#ifdef LOCAL
int main() {
    freopen("file.in", "r", stdin);
    int n; cin >> n;
    vector<vector<int>> p(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> p[i][j];
        }
    }
    cout << construct(p) << '\n';
    return 0;
}
#else
#endif

Compilation message

supertrees.cpp: In lambda function:
supertrees.cpp:35:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for (int i = 0; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
supertrees.cpp: In lambda function:
supertrees.cpp:44:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (int i = 0; i < v.size() - 1; i++) {
      |                         ~~^~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:80:38: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   80 |         if (overall[0] || overall[2] && overall[3]) {
supertrees.cpp:121:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |         for (int j = 0; j < chains.size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~
supertrees.cpp:122:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |             for (int k = j + 1; k < chains.size(); k++) {
      |                                 ~~^~~~~~~~~~~~~~~
supertrees.cpp:60:13: warning: unused variable 'sz' [-Wunused-variable]
   60 |         int sz = comp.size();
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 11 ms 1152 KB Output is correct
7 Correct 258 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 11 ms 1152 KB Output is correct
7 Correct 258 ms 22136 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 263 ms 22104 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 117 ms 12248 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 60 ms 5752 KB Output is correct
21 Correct 241 ms 22140 KB Output is correct
22 Correct 236 ms 22136 KB Output is correct
23 Correct 256 ms 22264 KB Output is correct
24 Correct 236 ms 22136 KB Output is correct
25 Correct 99 ms 12152 KB Output is correct
26 Correct 96 ms 12152 KB Output is correct
27 Correct 252 ms 22136 KB Output is correct
28 Correct 237 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 11 ms 1312 KB Output is correct
9 Correct 235 ms 22136 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 262 ms 22136 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 117 ms 12152 KB Output is correct
18 Correct 1 ms 288 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 60 ms 5836 KB Output is correct
22 Correct 240 ms 22136 KB Output is correct
23 Correct 237 ms 22136 KB Output is correct
24 Correct 253 ms 22136 KB Output is correct
25 Correct 94 ms 12152 KB Output is correct
26 Correct 98 ms 12156 KB Output is correct
27 Correct 232 ms 22136 KB Output is correct
28 Correct 257 ms 22136 KB Output is correct
29 Correct 94 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 60 ms 5832 KB Output is correct
5 Correct 242 ms 22136 KB Output is correct
6 Correct 234 ms 22136 KB Output is correct
7 Correct 258 ms 22104 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 59 ms 5752 KB Output is correct
10 Correct 242 ms 22168 KB Output is correct
11 Correct 235 ms 22136 KB Output is correct
12 Correct 256 ms 22136 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 60 ms 5752 KB Output is correct
17 Correct 238 ms 22264 KB Output is correct
18 Correct 256 ms 22136 KB Output is correct
19 Correct 235 ms 22136 KB Output is correct
20 Correct 235 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 11 ms 1152 KB Output is correct
7 Correct 258 ms 22136 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 263 ms 22104 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 117 ms 12248 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 60 ms 5752 KB Output is correct
21 Correct 241 ms 22140 KB Output is correct
22 Correct 236 ms 22136 KB Output is correct
23 Correct 256 ms 22264 KB Output is correct
24 Correct 236 ms 22136 KB Output is correct
25 Correct 99 ms 12152 KB Output is correct
26 Correct 96 ms 12152 KB Output is correct
27 Correct 252 ms 22136 KB Output is correct
28 Correct 237 ms 22136 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 0 ms 256 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 0 ms 256 KB Output is correct
35 Correct 0 ms 256 KB Output is correct
36 Correct 11 ms 1312 KB Output is correct
37 Correct 235 ms 22136 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 11 ms 1152 KB Output is correct
41 Correct 262 ms 22136 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 0 ms 256 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 117 ms 12152 KB Output is correct
46 Correct 1 ms 288 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 60 ms 5836 KB Output is correct
50 Correct 240 ms 22136 KB Output is correct
51 Correct 237 ms 22136 KB Output is correct
52 Correct 253 ms 22136 KB Output is correct
53 Correct 94 ms 12152 KB Output is correct
54 Correct 98 ms 12156 KB Output is correct
55 Correct 232 ms 22136 KB Output is correct
56 Correct 257 ms 22136 KB Output is correct
57 Correct 94 ms 12152 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 1 ms 256 KB Output is correct
60 Correct 5 ms 768 KB Output is correct
61 Correct 117 ms 12152 KB Output is correct
62 Correct 0 ms 256 KB Output is correct
63 Correct 1 ms 256 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Correct 59 ms 5756 KB Output is correct
66 Correct 99 ms 12156 KB Output is correct
67 Correct 100 ms 12152 KB Output is correct
68 Correct 94 ms 12152 KB Output is correct
69 Correct 102 ms 12124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 11 ms 1152 KB Output is correct
7 Correct 258 ms 22136 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 10 ms 1152 KB Output is correct
13 Correct 263 ms 22104 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 5 ms 768 KB Output is correct
17 Correct 117 ms 12248 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 60 ms 5752 KB Output is correct
21 Correct 241 ms 22140 KB Output is correct
22 Correct 236 ms 22136 KB Output is correct
23 Correct 256 ms 22264 KB Output is correct
24 Correct 236 ms 22136 KB Output is correct
25 Correct 99 ms 12152 KB Output is correct
26 Correct 96 ms 12152 KB Output is correct
27 Correct 252 ms 22136 KB Output is correct
28 Correct 237 ms 22136 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 0 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 0 ms 256 KB Output is correct
33 Correct 1 ms 256 KB Output is correct
34 Correct 0 ms 256 KB Output is correct
35 Correct 0 ms 256 KB Output is correct
36 Correct 11 ms 1312 KB Output is correct
37 Correct 235 ms 22136 KB Output is correct
38 Correct 1 ms 256 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 11 ms 1152 KB Output is correct
41 Correct 262 ms 22136 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 0 ms 256 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 117 ms 12152 KB Output is correct
46 Correct 1 ms 288 KB Output is correct
47 Correct 1 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 60 ms 5836 KB Output is correct
50 Correct 240 ms 22136 KB Output is correct
51 Correct 237 ms 22136 KB Output is correct
52 Correct 253 ms 22136 KB Output is correct
53 Correct 94 ms 12152 KB Output is correct
54 Correct 98 ms 12156 KB Output is correct
55 Correct 232 ms 22136 KB Output is correct
56 Correct 257 ms 22136 KB Output is correct
57 Correct 94 ms 12152 KB Output is correct
58 Correct 1 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 1 ms 256 KB Output is correct
61 Correct 60 ms 5832 KB Output is correct
62 Correct 242 ms 22136 KB Output is correct
63 Correct 234 ms 22136 KB Output is correct
64 Correct 258 ms 22104 KB Output is correct
65 Correct 1 ms 256 KB Output is correct
66 Correct 59 ms 5752 KB Output is correct
67 Correct 242 ms 22168 KB Output is correct
68 Correct 235 ms 22136 KB Output is correct
69 Correct 256 ms 22136 KB Output is correct
70 Correct 1 ms 256 KB Output is correct
71 Correct 1 ms 256 KB Output is correct
72 Correct 1 ms 256 KB Output is correct
73 Correct 60 ms 5752 KB Output is correct
74 Correct 238 ms 22264 KB Output is correct
75 Correct 256 ms 22136 KB Output is correct
76 Correct 235 ms 22136 KB Output is correct
77 Correct 235 ms 22136 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 1 ms 256 KB Output is correct
80 Correct 5 ms 768 KB Output is correct
81 Correct 117 ms 12152 KB Output is correct
82 Correct 0 ms 256 KB Output is correct
83 Correct 1 ms 256 KB Output is correct
84 Correct 1 ms 256 KB Output is correct
85 Correct 59 ms 5756 KB Output is correct
86 Correct 99 ms 12156 KB Output is correct
87 Correct 100 ms 12152 KB Output is correct
88 Correct 94 ms 12152 KB Output is correct
89 Correct 102 ms 12124 KB Output is correct
90 Correct 0 ms 256 KB Output is correct
91 Correct 1 ms 256 KB Output is correct
92 Correct 5 ms 768 KB Output is correct
93 Correct 122 ms 12152 KB Output is correct
94 Correct 0 ms 256 KB Output is correct
95 Correct 0 ms 256 KB Output is correct
96 Correct 0 ms 256 KB Output is correct
97 Correct 24 ms 3320 KB Output is correct
98 Correct 97 ms 12152 KB Output is correct
99 Correct 109 ms 12152 KB Output is correct
100 Correct 95 ms 12152 KB Output is correct
101 Correct 95 ms 12152 KB Output is correct
102 Incorrect 260 ms 22168 KB Answer gives possible 1 while actual possible 0
103 Halted 0 ms 0 KB -