Submission #610865

# Submission time Handle Problem Language Result Execution time Memory
610865 2022-07-28T16:34:17 Z nohaxjustsoflo Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
205 ms 22116 KB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//uniform_int_distribution<int> gen; ///(min, max)
//int random() {return gen(mt_rand);}
const int mxN=1001;
const int mod=998244353;
const int mxlogN=40;
const int mxK=26;
const int inf=1e9;
const int K=600;
struct DSU
{
    vector<int> size,p;
    int comp;
    void build(int n)
    {
        size=vector<int>(n,1);
        p=vector<int>(n);
        iota(p.begin(),p.end(),0);
        comp=n;
    }
    int get(int x)
    {
        if(p[x]^x) p[x]=get(p[x]);
        return p[x];
    }
    bool unite(int a, int b)
    {
        a=get(a),b=get(b);
        if(a==b) return 0;
        if(size[a]>size[b]) swap(a,b);
        p[a]=b;
        size[b]+=size[a];
        comp--;
        return 1;
    }
};
vector<int> who[mxN];
void build(vector<vector<int>> b);
int construct(vector<vector<int>> p)
{
	int n=p.size();
	DSU dsu; dsu.build(n);
	for(int j=0; j<n; j++) for(int i=j+1; i<n; i++)
    {
        if(p[j][i]==3) return 0;
        if(p[j][i]) dsu.unite(j,i);
    }
	for(int i=0; i<n; i++) who[dsu.get(i)].push_back(i);
	vector<vector<int>> answ(n,vector<int>(n,0));
	for(int o=0; o<n; o++)
    {
        if(dsu.get(o)==o)
        {
            vector<int> a=who[o];
            for(int i:a) for(int j:a) if(!p[i][j]) return 0;
            map<vector<int>, vector<int>> mp;
            for(int i:a)
            {
                vector<int> b;
                for(int j:a) b.push_back(p[i][j]);
                mp[b].push_back(i);
            }
            if(mp.size()==2) return 0;
            vector<int> b;
            for(auto& par:mp)
            {
                int i=par.second[0];
                b.push_back(i);
                for(int j:par.second) if(i^j) answ[i][j]=answ[j][i]=1;
            }
            if(b.size()>1)
            for(int i=0; i<b.size(); i++)
            {
                int j=i+1;
                if(j==b.size()) j=0;
                int l=b[i], r=b[j];
                answ[l][r]=answ[r][l]=1;
            }
        }
    }
    build(answ);
	return 1;
}

/*
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);


}

*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:82:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |             for(int i=0; i<b.size(); i++)
      |                          ~^~~~~~~~~
supertrees.cpp:85:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |                 if(j==b.size()) j=0;
      |                    ~^~~~~~~~~~
# 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 7 ms 1108 KB Output is correct
7 Correct 157 ms 22084 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 7 ms 1108 KB Output is correct
7 Correct 157 ms 22084 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 1192 KB Output is correct
13 Correct 170 ms 22048 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 12072 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 43 ms 5708 KB Output is correct
21 Correct 167 ms 22040 KB Output is correct
22 Correct 156 ms 22060 KB Output is correct
23 Correct 165 ms 22044 KB Output is correct
24 Correct 158 ms 22088 KB Output is correct
25 Correct 69 ms 12068 KB Output is correct
26 Correct 76 ms 12072 KB Output is correct
27 Correct 164 ms 22064 KB Output is correct
28 Correct 161 ms 22092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 7 ms 1192 KB Output is correct
9 Correct 175 ms 22048 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 8 ms 1124 KB Output is correct
13 Correct 166 ms 22040 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 74 ms 12080 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 39 ms 5708 KB Output is correct
22 Correct 157 ms 22056 KB Output is correct
23 Correct 153 ms 22052 KB Output is correct
24 Correct 169 ms 22044 KB Output is correct
25 Correct 68 ms 12200 KB Output is correct
26 Correct 69 ms 12200 KB Output is correct
27 Correct 164 ms 22048 KB Output is correct
28 Correct 173 ms 22116 KB Output is correct
29 Correct 71 ms 12192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 40 ms 5716 KB Output is correct
5 Correct 164 ms 22088 KB Output is correct
6 Correct 155 ms 22044 KB Output is correct
7 Correct 173 ms 22048 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 40 ms 5788 KB Output is correct
10 Correct 205 ms 22112 KB Output is correct
11 Correct 164 ms 22096 KB Output is correct
12 Correct 187 ms 22076 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 42 ms 5680 KB Output is correct
17 Correct 160 ms 22088 KB Output is correct
18 Correct 155 ms 22092 KB Output is correct
19 Correct 183 ms 22028 KB Output is correct
20 Correct 162 ms 22028 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 7 ms 1108 KB Output is correct
7 Correct 157 ms 22084 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 1192 KB Output is correct
13 Correct 170 ms 22048 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 12072 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 43 ms 5708 KB Output is correct
21 Correct 167 ms 22040 KB Output is correct
22 Correct 156 ms 22060 KB Output is correct
23 Correct 165 ms 22044 KB Output is correct
24 Correct 158 ms 22088 KB Output is correct
25 Correct 69 ms 12068 KB Output is correct
26 Correct 76 ms 12072 KB Output is correct
27 Correct 164 ms 22064 KB Output is correct
28 Correct 161 ms 22092 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 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 7 ms 1192 KB Output is correct
37 Correct 175 ms 22048 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1124 KB Output is correct
41 Correct 166 ms 22040 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 74 ms 12080 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 39 ms 5708 KB Output is correct
50 Correct 157 ms 22056 KB Output is correct
51 Correct 153 ms 22052 KB Output is correct
52 Correct 169 ms 22044 KB Output is correct
53 Correct 68 ms 12200 KB Output is correct
54 Correct 69 ms 12200 KB Output is correct
55 Correct 164 ms 22048 KB Output is correct
56 Correct 173 ms 22116 KB Output is correct
57 Correct 71 ms 12192 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 4 ms 724 KB Output is correct
61 Correct 76 ms 12060 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 42 ms 5792 KB Output is correct
66 Correct 72 ms 12200 KB Output is correct
67 Correct 68 ms 12192 KB Output is correct
68 Correct 69 ms 12072 KB Output is correct
69 Correct 68 ms 12080 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 7 ms 1108 KB Output is correct
7 Correct 157 ms 22084 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 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 1192 KB Output is correct
13 Correct 170 ms 22048 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 75 ms 12072 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 43 ms 5708 KB Output is correct
21 Correct 167 ms 22040 KB Output is correct
22 Correct 156 ms 22060 KB Output is correct
23 Correct 165 ms 22044 KB Output is correct
24 Correct 158 ms 22088 KB Output is correct
25 Correct 69 ms 12068 KB Output is correct
26 Correct 76 ms 12072 KB Output is correct
27 Correct 164 ms 22064 KB Output is correct
28 Correct 161 ms 22092 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 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 7 ms 1192 KB Output is correct
37 Correct 175 ms 22048 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 8 ms 1124 KB Output is correct
41 Correct 166 ms 22040 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 74 ms 12080 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 39 ms 5708 KB Output is correct
50 Correct 157 ms 22056 KB Output is correct
51 Correct 153 ms 22052 KB Output is correct
52 Correct 169 ms 22044 KB Output is correct
53 Correct 68 ms 12200 KB Output is correct
54 Correct 69 ms 12200 KB Output is correct
55 Correct 164 ms 22048 KB Output is correct
56 Correct 173 ms 22116 KB Output is correct
57 Correct 71 ms 12192 KB Output is correct
58 Correct 1 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 40 ms 5716 KB Output is correct
62 Correct 164 ms 22088 KB Output is correct
63 Correct 155 ms 22044 KB Output is correct
64 Correct 173 ms 22048 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 40 ms 5788 KB Output is correct
67 Correct 205 ms 22112 KB Output is correct
68 Correct 164 ms 22096 KB Output is correct
69 Correct 187 ms 22076 KB Output is correct
70 Correct 1 ms 212 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 42 ms 5680 KB Output is correct
74 Correct 160 ms 22088 KB Output is correct
75 Correct 155 ms 22092 KB Output is correct
76 Correct 183 ms 22028 KB Output is correct
77 Correct 162 ms 22028 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 1 ms 212 KB Output is correct
80 Correct 4 ms 724 KB Output is correct
81 Correct 76 ms 12060 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 42 ms 5792 KB Output is correct
86 Correct 72 ms 12200 KB Output is correct
87 Correct 68 ms 12192 KB Output is correct
88 Correct 69 ms 12072 KB Output is correct
89 Correct 68 ms 12080 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 3 ms 596 KB Output is correct
93 Correct 65 ms 8096 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 1 ms 212 KB Output is correct
97 Correct 16 ms 2260 KB Output is correct
98 Correct 67 ms 8092 KB Output is correct
99 Correct 66 ms 8104 KB Output is correct
100 Correct 67 ms 8108 KB Output is correct
101 Correct 66 ms 8092 KB Output is correct
102 Correct 62 ms 8140 KB Output is correct
103 Correct 62 ms 8108 KB Output is correct
104 Correct 62 ms 8096 KB Output is correct
105 Correct 69 ms 8140 KB Output is correct