Submission #720618

# Submission time Handle Problem Language Result Execution time Memory
720618 2023-04-08T16:27:56 Z bin9638 Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
196 ms 24236 KB
#include <bits/stdc++.h>

#ifndef SKY
#include "supertrees.h"
#endif // SKY

using namespace std;

#define N 1010
#define ll long long
#define fs first
#define sc second
#define ii pair<int,int>
#define pb push_back

int n,ktr[N];

#ifdef SKY
void build(vector<vector<int>>kq)
{
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)cout<<kq[i][j]<<" ";cout<<endl;
    }
}
#endif // SKY

struct DSU
{
    int lab[N];
    vector<int>lis[N];

    void init()
    {
        memset(lab,-1,sizeof(lab));
        for(int i=0;i<n;i++)
            lis[i].pb(i);
    }

    int root(int u)
    {
        if(lab[u]<0)
            return u;
        return(lab[u]=root(lab[u]));
    }

    bool update(int u,int v)
    {
        if((u=root(u))==(v=root(v)))
            return 0;
        if(lab[u]>lab[v])
            swap(u,v);
        lab[u]+=lab[v];
        lab[v]=u;
        for(auto x:lis[v])
            lis[u].pb(x);
        return 1;
    }
}T,D;

int construct(vector<vector<int>> p)
{
    n=p[0].size();
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(p[i][j]==3)
                return 0;
    T.init();
    D.init();
    vector<vector<int>>kq;
    kq.resize(n,vector<int>(n,0));
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(p[i][j]==1)
            {
                if(T.update(i,j)&&D.update(i,j))
                    kq[i][j]=kq[j][i]=1;
            }
    for(int i=0;i<n;i++)
    {
        D.lis[i].clear();
        if(D.root(i)==i)
            D.lis[i].pb(i);
    }
     for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            if(p[i][j]==2)
            {
                D.update(i,j);
            }
    //for(int i=0;i<n;i++)cout<<T.root(i)<<" "<<D.root(i)<<endl;
    for(int i=0;i<n;i++)
        if(D.root(i)==i&&D.lis[i].size()>1)
        {
            vector<int>s=D.lis[i];
            if(s.size()==2)
                return 0;
            kq[s[0]][s.back()]=kq[s.back()][s[0]]=1;
            for(int i=1;i<s.size();i++)
                kq[s[i-1]][s[i]]=kq[s[i]][s[i-1]]=1;
        }
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            if(p[i][j]==0)
            {
                if(D.root(i)==D.root(j))
                    return 0;
            }
            if(p[i][j]==1)
            {
                if(!(T.root(i)==T.root(j)&&D.root(i)==D.root(j)))
                    return 0;
            }
            if(p[i][j]==2)
            {
                if(!(T.root(i)!=T.root(j)&&D.root(i)==D.root(j)))
                    return 0;
            }
        }
    build(kq);
    return 1;
}

#ifdef SKY
int main()
{
    freopen("A.inp","r",stdin);
    freopen("A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vector<vector<int>>p;
    p.resize(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);
    return 0;
}
#endif

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:99:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |             for(int i=1;i<s.size();i++)
      |                         ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 179 ms 22124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 179 ms 22124 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 177 ms 22112 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 85 ms 12236 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 43 ms 5776 KB Output is correct
21 Correct 178 ms 22108 KB Output is correct
22 Correct 183 ms 22124 KB Output is correct
23 Correct 194 ms 22216 KB Output is correct
24 Correct 173 ms 22072 KB Output is correct
25 Correct 69 ms 12228 KB Output is correct
26 Correct 64 ms 12232 KB Output is correct
27 Correct 187 ms 22072 KB Output is correct
28 Correct 172 ms 22084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 8 ms 1236 KB Output is correct
9 Correct 177 ms 24112 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 8 ms 1268 KB Output is correct
13 Correct 186 ms 24048 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 85 ms 14132 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 47 ms 6236 KB Output is correct
22 Correct 182 ms 24040 KB Output is correct
23 Correct 178 ms 24120 KB Output is correct
24 Correct 192 ms 24112 KB Output is correct
25 Correct 72 ms 14152 KB Output is correct
26 Correct 71 ms 14136 KB Output is correct
27 Correct 176 ms 24124 KB Output is correct
28 Correct 196 ms 24236 KB Output is correct
29 Correct 64 ms 14132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 47 ms 5768 KB Output is correct
5 Correct 176 ms 22096 KB Output is correct
6 Correct 175 ms 22080 KB Output is correct
7 Correct 190 ms 22080 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 46 ms 5820 KB Output is correct
10 Correct 187 ms 22148 KB Output is correct
11 Correct 178 ms 22136 KB Output is correct
12 Correct 193 ms 22080 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 45 ms 5848 KB Output is correct
17 Correct 176 ms 22084 KB Output is correct
18 Correct 183 ms 22084 KB Output is correct
19 Correct 173 ms 22116 KB Output is correct
20 Correct 176 ms 22248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 179 ms 22124 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 177 ms 22112 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 85 ms 12236 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 43 ms 5776 KB Output is correct
21 Correct 178 ms 22108 KB Output is correct
22 Correct 183 ms 22124 KB Output is correct
23 Correct 194 ms 22216 KB Output is correct
24 Correct 173 ms 22072 KB Output is correct
25 Correct 69 ms 12228 KB Output is correct
26 Correct 64 ms 12232 KB Output is correct
27 Correct 187 ms 22072 KB Output is correct
28 Correct 172 ms 22084 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 8 ms 1236 KB Output is correct
37 Correct 177 ms 24112 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 8 ms 1268 KB Output is correct
41 Correct 186 ms 24048 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 352 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 85 ms 14132 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 47 ms 6236 KB Output is correct
50 Correct 182 ms 24040 KB Output is correct
51 Correct 178 ms 24120 KB Output is correct
52 Correct 192 ms 24112 KB Output is correct
53 Correct 72 ms 14152 KB Output is correct
54 Correct 71 ms 14136 KB Output is correct
55 Correct 176 ms 24124 KB Output is correct
56 Correct 196 ms 24236 KB Output is correct
57 Correct 64 ms 14132 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 5 ms 888 KB Output is correct
61 Correct 88 ms 14164 KB Output is correct
62 Correct 1 ms 356 KB Output is correct
63 Correct 1 ms 360 KB Output is correct
64 Correct 1 ms 364 KB Output is correct
65 Correct 47 ms 6352 KB Output is correct
66 Correct 70 ms 14128 KB Output is correct
67 Correct 73 ms 14136 KB Output is correct
68 Correct 67 ms 14180 KB Output is correct
69 Correct 74 ms 14136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 8 ms 1236 KB Output is correct
7 Correct 179 ms 22124 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 8 ms 1236 KB Output is correct
13 Correct 177 ms 22112 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 852 KB Output is correct
17 Correct 85 ms 12236 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 43 ms 5776 KB Output is correct
21 Correct 178 ms 22108 KB Output is correct
22 Correct 183 ms 22124 KB Output is correct
23 Correct 194 ms 22216 KB Output is correct
24 Correct 173 ms 22072 KB Output is correct
25 Correct 69 ms 12228 KB Output is correct
26 Correct 64 ms 12232 KB Output is correct
27 Correct 187 ms 22072 KB Output is correct
28 Correct 172 ms 22084 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 8 ms 1236 KB Output is correct
37 Correct 177 ms 24112 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 8 ms 1268 KB Output is correct
41 Correct 186 ms 24048 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 352 KB Output is correct
44 Correct 4 ms 852 KB Output is correct
45 Correct 85 ms 14132 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 47 ms 6236 KB Output is correct
50 Correct 182 ms 24040 KB Output is correct
51 Correct 178 ms 24120 KB Output is correct
52 Correct 192 ms 24112 KB Output is correct
53 Correct 72 ms 14152 KB Output is correct
54 Correct 71 ms 14136 KB Output is correct
55 Correct 176 ms 24124 KB Output is correct
56 Correct 196 ms 24236 KB Output is correct
57 Correct 64 ms 14132 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 47 ms 5768 KB Output is correct
62 Correct 176 ms 22096 KB Output is correct
63 Correct 175 ms 22080 KB Output is correct
64 Correct 190 ms 22080 KB Output is correct
65 Correct 0 ms 340 KB Output is correct
66 Correct 46 ms 5820 KB Output is correct
67 Correct 187 ms 22148 KB Output is correct
68 Correct 178 ms 22136 KB Output is correct
69 Correct 193 ms 22080 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 0 ms 340 KB Output is correct
73 Correct 45 ms 5848 KB Output is correct
74 Correct 176 ms 22084 KB Output is correct
75 Correct 183 ms 22084 KB Output is correct
76 Correct 173 ms 22116 KB Output is correct
77 Correct 176 ms 22248 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 5 ms 888 KB Output is correct
81 Correct 88 ms 14164 KB Output is correct
82 Correct 1 ms 356 KB Output is correct
83 Correct 1 ms 360 KB Output is correct
84 Correct 1 ms 364 KB Output is correct
85 Correct 47 ms 6352 KB Output is correct
86 Correct 70 ms 14128 KB Output is correct
87 Correct 73 ms 14136 KB Output is correct
88 Correct 67 ms 14180 KB Output is correct
89 Correct 74 ms 14136 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 4 ms 752 KB Output is correct
93 Correct 72 ms 10080 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 360 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 18 ms 2728 KB Output is correct
98 Correct 74 ms 10160 KB Output is correct
99 Correct 67 ms 10156 KB Output is correct
100 Correct 64 ms 10164 KB Output is correct
101 Correct 63 ms 10172 KB Output is correct
102 Correct 63 ms 10156 KB Output is correct
103 Correct 66 ms 10156 KB Output is correct
104 Correct 62 ms 10176 KB Output is correct
105 Correct 71 ms 10188 KB Output is correct