#include "supertrees.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define ft first
#define sd second
#define pi pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(...) dbg_out(__VA_ARGS__)
using ll = long long;
using ld = long double;
using namespace std;
using namespace __gnu_pbds;
//Constants
const ll INF = 5 * 1e18;
const int IINF = 2 * 1e9;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ld PI = 3.14159265359;
//Templates
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';}
void dbg_out() {cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); }
template<typename T> void mins(T& x, T y) {x = min(x, y);}
template<typename T> void maxs(T& x, T y) {x = max(x, y);}
template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using omset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
//order_of_key(k): number of elements strictly less than k
//find_by_order(k): k-th element in the set
void setPrec() {cout << fixed << setprecision(15);}
void unsyncIO() {cin.tie(0)->sync_with_stdio(0);}
void setIn(string s) {freopen(s.c_str(), "r", stdin);}
void setOut(string s) {freopen(s.c_str(), "w", stdout);}
void setIO(string s = "") {
unsyncIO(); setPrec();
if(s.size()) setIn(s + ".in"), setOut(s + ".out");
}
int construct(vector<vector<int>> p) {
int n = p.size();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (p[i][j] == 3) return 0;
}
}
// build cycles
vector<vector<int>> ans(n, vector<int> (n, 0));
vector<int> comp(n, -1);
int comp_num = 0;
{
vector<bool> vis(n, false);
vector<int> path;
function<void(int)> dfs = [&](int f) {
vis[f] = true;
path.pb(f);
for (int to = 0; to < n; to++) {
if (!vis[to] && p[f][to] == 2) {
dfs(to);
}
}
};
for (int i = 0; i < n; i++) {
if (!vis[i]) {
path.clear();
dfs(i);
if ((int) path.size() == 2) {
return 0;
}
if ((int) path.size() > 2) {
int sz = path.size();
for (int j = 0; j < sz; j++) {
for (int z = j + 1; z < sz; z++) {
if (p[path[j]][path[z]] != 2) {
return 0;
}
}
}
for (int j = 0; j < sz; j++) {
comp[path[j]] = comp_num;
ans[path[j]][path[(j + 1) % sz]] = ans[path[(j + 1) % sz]][path[j]] = 1;
}
comp_num++;
}
}
}
}
// build bamboos
{
vector<bool> vis(n, false);
vector<int> path; set<int> comps_vis;
function<void(int)> dfs = [&](int f) {
vis[f] = true;
path.pb(f);
for (int to = 0; to < n; to++) {
if (!vis[to]) {
if (p[f][to] == 1)
dfs(to);
else if (p[f][to] == 2)
comps_vis.insert(comp[to]);
}
}
};
for (int i = 0; i < n; i++) {
if (!vis[i]) {
comps_vis.clear();
path.clear();
dfs(i);
if ((int) comps_vis.size() > 1) {
return 0;
}
int sz = path.size();
for (int j = 0; j < sz; j++) {
for (int z = j + 1; z < sz; z++) {
if (p[path[j]][path[z]] != 1) {
return 0;
}
}
}
for (int j = 0; j < sz - 1; j++) {
ans[path[j]][path[j + 1]] = ans[path[j + 1]][path[j]] = 1;
}
}
}
}
build(ans);
return 1;
}
Compilation message
supertrees.cpp: In function 'void setIn(std::string)':
supertrees.cpp:43:30: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | void setIn(string s) {freopen(s.c_str(), "r", stdin);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp: In function 'void setOut(std::string)':
supertrees.cpp:44:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | void setOut(string s) {freopen(s.c_str(), "w", stdout);}
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
176 ms |
22072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
176 ms |
22072 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1140 KB |
Output is correct |
13 |
Correct |
167 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
84 ms |
12176 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
51 ms |
5764 KB |
Output is correct |
21 |
Correct |
163 ms |
22036 KB |
Output is correct |
22 |
Correct |
171 ms |
22032 KB |
Output is correct |
23 |
Correct |
180 ms |
22016 KB |
Output is correct |
24 |
Correct |
165 ms |
22016 KB |
Output is correct |
25 |
Correct |
69 ms |
12044 KB |
Output is correct |
26 |
Correct |
64 ms |
12108 KB |
Output is correct |
27 |
Correct |
235 ms |
21960 KB |
Output is correct |
28 |
Correct |
181 ms |
21996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
8 ms |
1168 KB |
Output is correct |
9 |
Correct |
169 ms |
21932 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1108 KB |
Output is correct |
13 |
Correct |
179 ms |
22112 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
852 KB |
Output is correct |
17 |
Correct |
82 ms |
13260 KB |
Output is correct |
18 |
Correct |
0 ms |
296 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
45 ms |
6220 KB |
Output is correct |
22 |
Correct |
180 ms |
23144 KB |
Output is correct |
23 |
Correct |
179 ms |
23124 KB |
Output is correct |
24 |
Correct |
208 ms |
23172 KB |
Output is correct |
25 |
Correct |
67 ms |
13228 KB |
Output is correct |
26 |
Correct |
77 ms |
13292 KB |
Output is correct |
27 |
Correct |
174 ms |
23196 KB |
Output is correct |
28 |
Correct |
177 ms |
23268 KB |
Output is correct |
29 |
Correct |
67 ms |
13176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
43 ms |
5764 KB |
Output is correct |
5 |
Correct |
167 ms |
22052 KB |
Output is correct |
6 |
Correct |
197 ms |
22020 KB |
Output is correct |
7 |
Correct |
208 ms |
22016 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
51 ms |
5764 KB |
Output is correct |
10 |
Correct |
175 ms |
21992 KB |
Output is correct |
11 |
Correct |
192 ms |
21924 KB |
Output is correct |
12 |
Correct |
180 ms |
22016 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
176 ms |
22072 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1140 KB |
Output is correct |
13 |
Correct |
167 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
84 ms |
12176 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
51 ms |
5764 KB |
Output is correct |
21 |
Correct |
163 ms |
22036 KB |
Output is correct |
22 |
Correct |
171 ms |
22032 KB |
Output is correct |
23 |
Correct |
180 ms |
22016 KB |
Output is correct |
24 |
Correct |
165 ms |
22016 KB |
Output is correct |
25 |
Correct |
69 ms |
12044 KB |
Output is correct |
26 |
Correct |
64 ms |
12108 KB |
Output is correct |
27 |
Correct |
235 ms |
21960 KB |
Output is correct |
28 |
Correct |
181 ms |
21996 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1168 KB |
Output is correct |
37 |
Correct |
169 ms |
21932 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1108 KB |
Output is correct |
41 |
Correct |
179 ms |
22112 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
6 ms |
852 KB |
Output is correct |
45 |
Correct |
82 ms |
13260 KB |
Output is correct |
46 |
Correct |
0 ms |
296 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
45 ms |
6220 KB |
Output is correct |
50 |
Correct |
180 ms |
23144 KB |
Output is correct |
51 |
Correct |
179 ms |
23124 KB |
Output is correct |
52 |
Correct |
208 ms |
23172 KB |
Output is correct |
53 |
Correct |
67 ms |
13228 KB |
Output is correct |
54 |
Correct |
77 ms |
13292 KB |
Output is correct |
55 |
Correct |
174 ms |
23196 KB |
Output is correct |
56 |
Correct |
177 ms |
23268 KB |
Output is correct |
57 |
Correct |
67 ms |
13176 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
5 ms |
852 KB |
Output is correct |
61 |
Correct |
95 ms |
13236 KB |
Output is correct |
62 |
Correct |
1 ms |
212 KB |
Output is correct |
63 |
Correct |
1 ms |
296 KB |
Output is correct |
64 |
Correct |
1 ms |
300 KB |
Output is correct |
65 |
Incorrect |
17 ms |
3700 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 |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
176 ms |
22072 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
7 ms |
1140 KB |
Output is correct |
13 |
Correct |
167 ms |
22020 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
4 ms |
724 KB |
Output is correct |
17 |
Correct |
84 ms |
12176 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
51 ms |
5764 KB |
Output is correct |
21 |
Correct |
163 ms |
22036 KB |
Output is correct |
22 |
Correct |
171 ms |
22032 KB |
Output is correct |
23 |
Correct |
180 ms |
22016 KB |
Output is correct |
24 |
Correct |
165 ms |
22016 KB |
Output is correct |
25 |
Correct |
69 ms |
12044 KB |
Output is correct |
26 |
Correct |
64 ms |
12108 KB |
Output is correct |
27 |
Correct |
235 ms |
21960 KB |
Output is correct |
28 |
Correct |
181 ms |
21996 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
8 ms |
1168 KB |
Output is correct |
37 |
Correct |
169 ms |
21932 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
7 ms |
1108 KB |
Output is correct |
41 |
Correct |
179 ms |
22112 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
6 ms |
852 KB |
Output is correct |
45 |
Correct |
82 ms |
13260 KB |
Output is correct |
46 |
Correct |
0 ms |
296 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
45 ms |
6220 KB |
Output is correct |
50 |
Correct |
180 ms |
23144 KB |
Output is correct |
51 |
Correct |
179 ms |
23124 KB |
Output is correct |
52 |
Correct |
208 ms |
23172 KB |
Output is correct |
53 |
Correct |
67 ms |
13228 KB |
Output is correct |
54 |
Correct |
77 ms |
13292 KB |
Output is correct |
55 |
Correct |
174 ms |
23196 KB |
Output is correct |
56 |
Correct |
177 ms |
23268 KB |
Output is correct |
57 |
Correct |
67 ms |
13176 KB |
Output is correct |
58 |
Correct |
0 ms |
212 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
43 ms |
5764 KB |
Output is correct |
62 |
Correct |
167 ms |
22052 KB |
Output is correct |
63 |
Correct |
197 ms |
22020 KB |
Output is correct |
64 |
Correct |
208 ms |
22016 KB |
Output is correct |
65 |
Correct |
0 ms |
212 KB |
Output is correct |
66 |
Correct |
51 ms |
5764 KB |
Output is correct |
67 |
Correct |
175 ms |
21992 KB |
Output is correct |
68 |
Correct |
192 ms |
21924 KB |
Output is correct |
69 |
Correct |
180 ms |
22016 KB |
Output is correct |
70 |
Correct |
0 ms |
212 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Incorrect |
1 ms |
212 KB |
Answer gives possible 0 while actual possible 1 |
73 |
Halted |
0 ms |
0 KB |
- |