Submission #301468

# Submission time Handle Problem Language Result Execution time Memory
301468 2020-09-18T01:32:51 Z 12tqian Connecting Supertrees (IOI20_supertrees) C++14
40 / 100
266 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;
        }
        vector<int> le;
        vector<int> ri;
        for (int x: one) {
            bool ok = false;
            for (int y: le) {
                if (p[x][y] != 1) {
                    ri.push_back(x);
                    ok = true;
                    break;
                }
            }
            if (ok == false) {
                le.push_back(x);
            }
        }
        for (int x: le) {
            for (int y: le) {
                if (x == y) continue;
                if (p[x][y] != 1) {
                    return 0;
                }
            }
        }
        for (int x: ri) {
            for (int y: ri) {
                if (x == y) continue;
                if (p[x][y] != 1) {
                    return 0;
                }
            }
        }
        for (int x: le) {
            for (int y: ri) {
                if (overall[2] && p[x][y] != 2) {
                    return 0;
                }
                if (overall[3] && p[x][y] != 3) {
                    return 0;
                }
            }
        }
        int cycle = (le.size() ? 1 : 0) + (ri.size() ? 1 : 0) + other.size();
        if (overall[2]) {
            if (cycle < 3) {
                return 0;
            }
            if (le.size() == 0 && ri.size() == 0) {
                make_cycle(other);
                for (int j = 0; j < other.size(); j++) {
                    ae(other[j], other[(j + 1) % other.size()]);
                }
            } else if (le.size() == 0) {
                other.push_back(ri[0]);
                make_cycle(other);
                make_chain(ri);
            } else if (ri.size() == 0) {
                other.push_back(le[0]);
                make_cycle(other);
                make_chain(le);
            } else {
                other.push_back(le[0]);
                other.push_back(ri[0]);
                make_cycle(other);
                make_chain(le);
                make_chain(ri);
            }
        } else if (overall[3]) {
            if (cycle < 4) {
                return 0;
            }
            if (le.size() == 0 && ri.size() == 0) {
                make_triple(other);
                for (int j = 0; j < other.size(); j++) {
                    ae(other[j], other[(j + 1) % other.size()]);
                }
            } else if (le.size() == 0) {
                other.push_back(ri[0]);
                make_triple(other);
                make_chain(ri);
            } else if (ri.size() == 0) {
                other.push_back(le[0]);
                make_triple(other);
                make_chain(le);
            } else {
                other.push_back(le[0]);
                other.push_back(ri[0]);
                make_triple(other);
                make_chain(le);
                make_chain(ri);
            }
        } 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() {
    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];
        }
    }
    construct(p);
    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:131:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |                 for (int j = 0; j < other.size(); j++) {
      |                                 ~~^~~~~~~~~~~~~~
supertrees.cpp:155:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  155 |                 for (int j = 0; j < other.size(); j++) {
      |                                 ~~^~~~~~~~~~~~~~
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 0 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 11 ms 1152 KB Output is correct
7 Correct 266 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 0 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 11 ms 1152 KB Output is correct
7 Correct 266 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 1 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 241 ms 22168 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 121 ms 12152 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 60 ms 5816 KB Output is correct
21 Correct 242 ms 22136 KB Output is correct
22 Correct 235 ms 22136 KB Output is correct
23 Correct 257 ms 22136 KB Output is correct
24 Correct 255 ms 22136 KB Output is correct
25 Correct 107 ms 12152 KB Output is correct
26 Correct 107 ms 12120 KB Output is correct
27 Correct 258 ms 22136 KB Output is correct
28 Correct 240 ms 22112 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 15 ms 1152 KB Output is correct
9 Correct 238 ms 22136 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 12 ms 1152 KB Output is correct
13 Correct 261 ms 22136 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 121 ms 12280 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 60 ms 5752 KB Output is correct
22 Correct 246 ms 22104 KB Output is correct
23 Correct 249 ms 22136 KB Output is correct
24 Correct 260 ms 22136 KB Output is correct
25 Correct 103 ms 12152 KB Output is correct
26 Correct 109 ms 12152 KB Output is correct
27 Correct 243 ms 22092 KB Output is correct
28 Correct 254 ms 22264 KB Output is correct
29 Correct 113 ms 12280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 63 ms 5752 KB Output is correct
5 Correct 239 ms 22136 KB Output is correct
6 Correct 239 ms 22136 KB Output is correct
7 Correct 256 ms 22264 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 63 ms 5752 KB Output is correct
10 Correct 255 ms 22264 KB Output is correct
11 Correct 236 ms 22136 KB Output is correct
12 Correct 258 ms 22264 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Incorrect 26 ms 3328 KB Answer gives possible 0 while actual possible 1
17 Halted 0 ms 0 KB -
# 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 0 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 11 ms 1152 KB Output is correct
7 Correct 266 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 1 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 241 ms 22168 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 121 ms 12152 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 60 ms 5816 KB Output is correct
21 Correct 242 ms 22136 KB Output is correct
22 Correct 235 ms 22136 KB Output is correct
23 Correct 257 ms 22136 KB Output is correct
24 Correct 255 ms 22136 KB Output is correct
25 Correct 107 ms 12152 KB Output is correct
26 Correct 107 ms 12120 KB Output is correct
27 Correct 258 ms 22136 KB Output is correct
28 Correct 240 ms 22112 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 15 ms 1152 KB Output is correct
37 Correct 238 ms 22136 KB Output is correct
38 Correct 0 ms 256 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 12 ms 1152 KB Output is correct
41 Correct 261 ms 22136 KB Output is correct
42 Correct 0 ms 256 KB Output is correct
43 Correct 0 ms 256 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 121 ms 12280 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 60 ms 5752 KB Output is correct
50 Correct 246 ms 22104 KB Output is correct
51 Correct 249 ms 22136 KB Output is correct
52 Correct 260 ms 22136 KB Output is correct
53 Correct 103 ms 12152 KB Output is correct
54 Correct 109 ms 12152 KB Output is correct
55 Correct 243 ms 22092 KB Output is correct
56 Correct 254 ms 22264 KB Output is correct
57 Correct 113 ms 12280 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 6 ms 768 KB Output is correct
61 Correct 122 ms 12152 KB Output is correct
62 Correct 1 ms 256 KB Output is correct
63 Correct 0 ms 256 KB Output is correct
64 Correct 1 ms 256 KB Output is correct
65 Incorrect 28 ms 3320 KB Answer gives possible 0 while actual possible 1
66 Halted 0 ms 0 KB -
# 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 0 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 11 ms 1152 KB Output is correct
7 Correct 266 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 1 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 241 ms 22168 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 121 ms 12152 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 60 ms 5816 KB Output is correct
21 Correct 242 ms 22136 KB Output is correct
22 Correct 235 ms 22136 KB Output is correct
23 Correct 257 ms 22136 KB Output is correct
24 Correct 255 ms 22136 KB Output is correct
25 Correct 107 ms 12152 KB Output is correct
26 Correct 107 ms 12120 KB Output is correct
27 Correct 258 ms 22136 KB Output is correct
28 Correct 240 ms 22112 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 15 ms 1152 KB Output is correct
37 Correct 238 ms 22136 KB Output is correct
38 Correct 0 ms 256 KB Output is correct
39 Correct 0 ms 256 KB Output is correct
40 Correct 12 ms 1152 KB Output is correct
41 Correct 261 ms 22136 KB Output is correct
42 Correct 0 ms 256 KB Output is correct
43 Correct 0 ms 256 KB Output is correct
44 Correct 5 ms 768 KB Output is correct
45 Correct 121 ms 12280 KB Output is correct
46 Correct 0 ms 384 KB Output is correct
47 Correct 0 ms 256 KB Output is correct
48 Correct 0 ms 256 KB Output is correct
49 Correct 60 ms 5752 KB Output is correct
50 Correct 246 ms 22104 KB Output is correct
51 Correct 249 ms 22136 KB Output is correct
52 Correct 260 ms 22136 KB Output is correct
53 Correct 103 ms 12152 KB Output is correct
54 Correct 109 ms 12152 KB Output is correct
55 Correct 243 ms 22092 KB Output is correct
56 Correct 254 ms 22264 KB Output is correct
57 Correct 113 ms 12280 KB Output is correct
58 Correct 0 ms 256 KB Output is correct
59 Correct 0 ms 256 KB Output is correct
60 Correct 0 ms 256 KB Output is correct
61 Correct 63 ms 5752 KB Output is correct
62 Correct 239 ms 22136 KB Output is correct
63 Correct 239 ms 22136 KB Output is correct
64 Correct 256 ms 22264 KB Output is correct
65 Correct 0 ms 256 KB Output is correct
66 Correct 63 ms 5752 KB Output is correct
67 Correct 255 ms 22264 KB Output is correct
68 Correct 236 ms 22136 KB Output is correct
69 Correct 258 ms 22264 KB Output is correct
70 Correct 1 ms 256 KB Output is correct
71 Correct 0 ms 256 KB Output is correct
72 Correct 0 ms 256 KB Output is correct
73 Incorrect 26 ms 3328 KB Answer gives possible 0 while actual possible 1
74 Halted 0 ms 0 KB -