Submission #610850

# Submission time Handle Problem Language Result Execution time Memory
610850 2022-07-28T16:09:49 Z nohaxjustsoflo Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
180 ms 22184 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]) 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];
            bool ok=1;
            bool has2=0, has3=0;
            for(int i:a) for(int j:a)
            {
                if(!p[i][j]) ok=0;
                else if(p[i][j]==2) has2=1;
                else if(p[i][j]==3) has3=1;
            }
            if(has2&&has3) ok=0;
            if(!ok) return 0;
            if(!has2&&!has3)
            {
                int i=a[0];
                for(int j:a) if(i^j) answ[i][j]=answ[j][i]=1;
                continue;
            }
            if(has3) return 0;
            map<vector<int>, vector<int>> mp;
            int v=2+has3;
            vector<int> zasebni;
            for(int i:a)
            {
                vector<int> b;
                for(int j:a) b.push_back(p[i][j]);
                if(b!=vector<int>(a.size(),v)) mp[b].push_back(i);
                else zasebni.push_back(i);
            }
            if(zasebni.size()+mp.size()<=v) return 0;
            for(auto& par:mp)
            {
                sort(par.second.begin(),par.second.end());
                int i=par.second[0];
                for(int j:a)
                {
                    auto it=lower_bound(par.second.begin(),par.second.end(),j);
                    if(it!=par.second.end()&&*it==j)
                    {
                        ///nalazi se u ovoj grupi
                        //if(p[i][j]!=1) return 0;
                    }
                    else
                    {
                        ///druga grupa
                        //if(p[i][j]!=v) return 0;
                    }
                }
                zasebni.push_back(i);
                for(int j:par.second) if(i^j) answ[i][j]=answ[j][i]=1;
            }
            for(int i=0; i<zasebni.size(); i++)
            {
                int j=i+1;
                if(j==zasebni.size()) j=0;
                int l=zasebni[i], r=zasebni[j];
                answ[l][r]=answ[r][l]=1;
            }
            if(v==3)
            {
                int l=zasebni[0], r=zasebni[2];
                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:88:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   88 |             if(zasebni.size()+mp.size()<=v) return 0;
      |                ~~~~~~~~~~~~~~~~~~~~~~~~^~~
supertrees.cpp:110:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |             for(int i=0; i<zasebni.size(); i++)
      |                          ~^~~~~~~~~~~~~~~
supertrees.cpp:113:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |                 if(j==zasebni.size()) j=0;
      |                    ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 1128 KB Output is correct
7 Correct 154 ms 22044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 1128 KB Output is correct
7 Correct 154 ms 22044 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1132 KB Output is correct
13 Correct 157 ms 22120 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 79 ms 12068 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 49 ms 5776 KB Output is correct
21 Correct 150 ms 22092 KB Output is correct
22 Correct 151 ms 22064 KB Output is correct
23 Correct 164 ms 21968 KB Output is correct
24 Correct 146 ms 21992 KB Output is correct
25 Correct 65 ms 12072 KB Output is correct
26 Correct 61 ms 12064 KB Output is correct
27 Correct 155 ms 22056 KB Output is correct
28 Correct 152 ms 22048 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 1 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 7 ms 1108 KB Output is correct
9 Correct 180 ms 22060 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 8 ms 1108 KB Output is correct
13 Correct 162 ms 22060 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 98 ms 12108 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 40 ms 5792 KB Output is correct
22 Correct 157 ms 22060 KB Output is correct
23 Correct 156 ms 22092 KB Output is correct
24 Correct 163 ms 22092 KB Output is correct
25 Correct 62 ms 12192 KB Output is correct
26 Correct 87 ms 12188 KB Output is correct
27 Correct 157 ms 21972 KB Output is correct
28 Correct 166 ms 22176 KB Output is correct
29 Correct 77 ms 12108 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 39 ms 5696 KB Output is correct
5 Correct 153 ms 22184 KB Output is correct
6 Correct 164 ms 22048 KB Output is correct
7 Correct 157 ms 22176 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 50 ms 5792 KB Output is correct
10 Correct 154 ms 22132 KB Output is correct
11 Correct 152 ms 22060 KB Output is correct
12 Correct 166 ms 22060 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 41 ms 5704 KB Output is correct
17 Correct 175 ms 22064 KB Output is correct
18 Correct 161 ms 22092 KB Output is correct
19 Correct 151 ms 22096 KB Output is correct
20 Correct 152 ms 22104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 1128 KB Output is correct
7 Correct 154 ms 22044 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1132 KB Output is correct
13 Correct 157 ms 22120 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 79 ms 12068 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 49 ms 5776 KB Output is correct
21 Correct 150 ms 22092 KB Output is correct
22 Correct 151 ms 22064 KB Output is correct
23 Correct 164 ms 21968 KB Output is correct
24 Correct 146 ms 21992 KB Output is correct
25 Correct 65 ms 12072 KB Output is correct
26 Correct 61 ms 12064 KB Output is correct
27 Correct 155 ms 22056 KB Output is correct
28 Correct 152 ms 22048 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 1 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 7 ms 1108 KB Output is correct
37 Correct 180 ms 22060 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 288 KB Output is correct
40 Correct 8 ms 1108 KB Output is correct
41 Correct 162 ms 22060 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 5 ms 724 KB Output is correct
45 Correct 98 ms 12108 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 40 ms 5792 KB Output is correct
50 Correct 157 ms 22060 KB Output is correct
51 Correct 156 ms 22092 KB Output is correct
52 Correct 163 ms 22092 KB Output is correct
53 Correct 62 ms 12192 KB Output is correct
54 Correct 87 ms 12188 KB Output is correct
55 Correct 157 ms 21972 KB Output is correct
56 Correct 166 ms 22176 KB Output is correct
57 Correct 77 ms 12108 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 4 ms 724 KB Output is correct
61 Correct 79 ms 12072 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 38 ms 5716 KB Output is correct
66 Correct 68 ms 12192 KB Output is correct
67 Correct 72 ms 12192 KB Output is correct
68 Correct 81 ms 12192 KB Output is correct
69 Correct 62 ms 12192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 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 1128 KB Output is correct
7 Correct 154 ms 22044 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 1 ms 212 KB Output is correct
12 Correct 7 ms 1132 KB Output is correct
13 Correct 157 ms 22120 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 79 ms 12068 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 49 ms 5776 KB Output is correct
21 Correct 150 ms 22092 KB Output is correct
22 Correct 151 ms 22064 KB Output is correct
23 Correct 164 ms 21968 KB Output is correct
24 Correct 146 ms 21992 KB Output is correct
25 Correct 65 ms 12072 KB Output is correct
26 Correct 61 ms 12064 KB Output is correct
27 Correct 155 ms 22056 KB Output is correct
28 Correct 152 ms 22048 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 1 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 7 ms 1108 KB Output is correct
37 Correct 180 ms 22060 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 288 KB Output is correct
40 Correct 8 ms 1108 KB Output is correct
41 Correct 162 ms 22060 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 5 ms 724 KB Output is correct
45 Correct 98 ms 12108 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 40 ms 5792 KB Output is correct
50 Correct 157 ms 22060 KB Output is correct
51 Correct 156 ms 22092 KB Output is correct
52 Correct 163 ms 22092 KB Output is correct
53 Correct 62 ms 12192 KB Output is correct
54 Correct 87 ms 12188 KB Output is correct
55 Correct 157 ms 21972 KB Output is correct
56 Correct 166 ms 22176 KB Output is correct
57 Correct 77 ms 12108 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 39 ms 5696 KB Output is correct
62 Correct 153 ms 22184 KB Output is correct
63 Correct 164 ms 22048 KB Output is correct
64 Correct 157 ms 22176 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 50 ms 5792 KB Output is correct
67 Correct 154 ms 22132 KB Output is correct
68 Correct 152 ms 22060 KB Output is correct
69 Correct 166 ms 22060 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 41 ms 5704 KB Output is correct
74 Correct 175 ms 22064 KB Output is correct
75 Correct 161 ms 22092 KB Output is correct
76 Correct 151 ms 22096 KB Output is correct
77 Correct 152 ms 22104 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 4 ms 724 KB Output is correct
81 Correct 79 ms 12072 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 0 ms 212 KB Output is correct
85 Correct 38 ms 5716 KB Output is correct
86 Correct 68 ms 12192 KB Output is correct
87 Correct 72 ms 12192 KB Output is correct
88 Correct 81 ms 12192 KB Output is correct
89 Correct 62 ms 12192 KB Output is correct
90 Correct 0 ms 212 KB Output is correct
91 Correct 0 ms 212 KB Output is correct
92 Correct 4 ms 724 KB Output is correct
93 Correct 76 ms 12072 KB Output is correct
94 Correct 0 ms 212 KB Output is correct
95 Correct 0 ms 212 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Correct 18 ms 3248 KB Output is correct
98 Correct 67 ms 12068 KB Output is correct
99 Correct 72 ms 12192 KB Output is correct
100 Correct 67 ms 12072 KB Output is correct
101 Correct 62 ms 12192 KB Output is correct
102 Correct 65 ms 12108 KB Output is correct
103 Correct 71 ms 12196 KB Output is correct
104 Correct 66 ms 12236 KB Output is correct
105 Correct 79 ms 12220 KB Output is correct