답안 #392291

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392291 2021-04-20T18:53:03 Z Enkognit 슈퍼트리 잇기 (IOI20_supertrees) C++14
100 / 100
293 ms 23060 KB
#include <bits/stdc++.h>
#include "supertrees.h"
#define ll long long
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define fi first
#define se second
#define pii pair<int,int>

using namespace std;

int d[1005], T;
vector<vector<int> > b;
vector<int> c[2005], v[2005], e[2005];
bool tt[2005], tl[2005];

struct dsu
{
    ll d[2005];

    void make_sets(int h)
    {
        for (int i = 0; i < h; i++) d[i]=i;
    }

    ll find_set(int h)
    {
        if (h==d[h]) return h; else return d[h]=find_set(d[h]);
    }

    void unite_sets(int x,int y)
    {
        x=find_set(x);
        y=find_set(y);
        d[x]=y;
    }
} g, gg;


void dfs(int h)
{
    tt[h]=1;
    d[h]++;
    for (int i = 0; i < c[h].size(); i++)
        if (!tt[c[h][i]])
        {
            dfs(c[h][i]);
        }
    tt[h]=0;
}

int construct(vector<vector<int> > a)
{
    ll n=a.size();
    b.resize(n);
    for (int i = 0; i < n; i++)
        b[i].resize(n, 0);

    g.make_sets(n);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (a[i][j]==1)
                g.unite_sets(i, j); else
            if (a[i][j]==3)
                return 0;

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            if (a[i][j]!=1 && g.find_set(i)==g.find_set(j))
            {
                return 0;
            }
    vector<ll> z;
    for (int i = 0; i < n; i++)
    {
        if (g.find_set(i)==i)
        {
            z.pb(i);
        }
        v[g.find_set(i)].pb(i);
    }

    for (int i = 0; i < z.size(); i++)
    {
        for (int u = 0; u < v[z[i]].size()-1; u++)
        {
            b[v[z[i]][u+1]][v[z[i]][u]]=1;
            b[v[z[i]][u]][v[z[i]][u+1]]=1;
            c[v[z[i]][u+1]].pb(v[z[i]][u]);
            c[v[z[i]][u]].pb(v[z[i]][u+1]);
        }
    }
    gg.make_sets(n);
    for (int i = 0; i < z.size(); i++)
        for (int j = 0; j < z.size(); j++)
        {
            ll p=-1;
            for (int u = 0; u < v[z[i]].size(); u++)
                for (int q = 0; q < v[z[j]].size(); q++)
                    if (p==-1) p=a[v[z[i]][u]][v[z[j]][q]]; else
                    if (p!=a[v[z[i]][u]][v[z[j]][q]]) return 0;
            if (p==2)
                gg.unite_sets(z[i], z[j]);
        }

    for (int i = 0; i < z.size(); i++)
        for (int j = 0; j < z.size(); j++)
    {
        ll p=-1;
        for (int u = 0; u < v[z[i]].size(); u++)
            for (int q = 0; q < v[z[j]].size(); q++)
                if (p==-1) p=a[v[z[i]][u]][v[z[j]][q]]; else
                if (p!=a[v[z[i]][u]][v[z[j]][q]]) return 0;
        if (p==0 && gg.find_set(z[i])==gg.find_set(z[j]))
            return 0;
    }

    for (int i = 0; i < z.size(); i++)
        e[gg.find_set(z[i])].pb(z[i]);

    for (int i = 0; i < z.size(); i++)
        if (gg.find_set(z[i])==z[i])
        {
            if (e[z[i]].size()==2)
            {
                return 0;
            }
            if (e[z[i]].size()==1) continue;
            for (int j = 0; j < e[z[i]].size(); j++)
            {
                ll u=(j+1)%((int)e[z[i]].size());
                b[e[z[i]][j]][e[z[i]][u]]=1;
                b[e[z[i]][u]][e[z[i]][j]]=1;
                c[e[z[i]][j]].pb(e[z[i]][u]);
                c[e[z[i]][u]].pb(e[z[i]][j]);
            }
        }

    /*for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
    }*/

    build(b);

    return 1;
}

Compilation message

supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i = 0; i < c[h].size(); i++)
      |                     ~~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:86:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |     for (int i = 0; i < z.size(); i++)
      |                     ~~^~~~~~~~~~
supertrees.cpp:88:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for (int u = 0; u < v[z[i]].size()-1; u++)
      |                         ~~^~~~~~~~~~~~~~~~~~
supertrees.cpp:97:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for (int i = 0; i < z.size(); i++)
      |                     ~~^~~~~~~~~~
supertrees.cpp:98:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |         for (int j = 0; j < z.size(); j++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:101:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |             for (int u = 0; u < v[z[i]].size(); u++)
      |                             ~~^~~~~~~~~~~~~~~~
supertrees.cpp:102:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |                 for (int q = 0; q < v[z[j]].size(); q++)
      |                                 ~~^~~~~~~~~~~~~~~~
supertrees.cpp:109:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     for (int i = 0; i < z.size(); i++)
      |                     ~~^~~~~~~~~~
supertrees.cpp:110:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |         for (int j = 0; j < z.size(); j++)
      |                         ~~^~~~~~~~~~
supertrees.cpp:113:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |         for (int u = 0; u < v[z[i]].size(); u++)
      |                         ~~^~~~~~~~~~~~~~~~
supertrees.cpp:114:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |             for (int q = 0; q < v[z[j]].size(); q++)
      |                             ~~^~~~~~~~~~~~~~~~
supertrees.cpp:121:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |     for (int i = 0; i < z.size(); i++)
      |                     ~~^~~~~~~~~~
supertrees.cpp:124:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |     for (int i = 0; i < z.size(); i++)
      |                     ~~^~~~~~~~~~
supertrees.cpp:132:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  132 |             for (int j = 0; j < e[z[i]].size(); j++)
      |                             ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1372 KB Output is correct
7 Correct 244 ms 22932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1372 KB Output is correct
7 Correct 244 ms 22932 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1356 KB Output is correct
13 Correct 258 ms 22980 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 944 KB Output is correct
17 Correct 142 ms 12948 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 65 ms 6340 KB Output is correct
21 Correct 256 ms 22916 KB Output is correct
22 Correct 264 ms 22916 KB Output is correct
23 Correct 262 ms 22920 KB Output is correct
24 Correct 258 ms 22928 KB Output is correct
25 Correct 109 ms 12940 KB Output is correct
26 Correct 100 ms 12940 KB Output is correct
27 Correct 262 ms 22952 KB Output is correct
28 Correct 262 ms 22996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 11 ms 1384 KB Output is correct
9 Correct 293 ms 23004 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 14 ms 1408 KB Output is correct
13 Correct 260 ms 23056 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 972 KB Output is correct
17 Correct 152 ms 13100 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 69 ms 6344 KB Output is correct
22 Correct 271 ms 23008 KB Output is correct
23 Correct 266 ms 22980 KB Output is correct
24 Correct 291 ms 23060 KB Output is correct
25 Correct 118 ms 13124 KB Output is correct
26 Correct 115 ms 13204 KB Output is correct
27 Correct 270 ms 22956 KB Output is correct
28 Correct 290 ms 22980 KB Output is correct
29 Correct 124 ms 13076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 66 ms 6328 KB Output is correct
5 Correct 267 ms 22948 KB Output is correct
6 Correct 267 ms 22948 KB Output is correct
7 Correct 254 ms 23008 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 69 ms 6396 KB Output is correct
10 Correct 267 ms 22928 KB Output is correct
11 Correct 278 ms 23052 KB Output is correct
12 Correct 290 ms 23000 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 68 ms 6428 KB Output is correct
17 Correct 268 ms 23052 KB Output is correct
18 Correct 271 ms 22936 KB Output is correct
19 Correct 282 ms 22932 KB Output is correct
20 Correct 260 ms 23036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1372 KB Output is correct
7 Correct 244 ms 22932 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1356 KB Output is correct
13 Correct 258 ms 22980 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 944 KB Output is correct
17 Correct 142 ms 12948 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 65 ms 6340 KB Output is correct
21 Correct 256 ms 22916 KB Output is correct
22 Correct 264 ms 22916 KB Output is correct
23 Correct 262 ms 22920 KB Output is correct
24 Correct 258 ms 22928 KB Output is correct
25 Correct 109 ms 12940 KB Output is correct
26 Correct 100 ms 12940 KB Output is correct
27 Correct 262 ms 22952 KB Output is correct
28 Correct 262 ms 22996 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 11 ms 1384 KB Output is correct
37 Correct 293 ms 23004 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 14 ms 1408 KB Output is correct
41 Correct 260 ms 23056 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 6 ms 972 KB Output is correct
45 Correct 152 ms 13100 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 69 ms 6344 KB Output is correct
50 Correct 271 ms 23008 KB Output is correct
51 Correct 266 ms 22980 KB Output is correct
52 Correct 291 ms 23060 KB Output is correct
53 Correct 118 ms 13124 KB Output is correct
54 Correct 115 ms 13204 KB Output is correct
55 Correct 270 ms 22956 KB Output is correct
56 Correct 290 ms 22980 KB Output is correct
57 Correct 124 ms 13076 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 5 ms 972 KB Output is correct
61 Correct 105 ms 12944 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 70 ms 6396 KB Output is correct
66 Correct 107 ms 13072 KB Output is correct
67 Correct 112 ms 12932 KB Output is correct
68 Correct 106 ms 13100 KB Output is correct
69 Correct 119 ms 13068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 11 ms 1372 KB Output is correct
7 Correct 244 ms 22932 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 11 ms 1356 KB Output is correct
13 Correct 258 ms 22980 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 944 KB Output is correct
17 Correct 142 ms 12948 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 65 ms 6340 KB Output is correct
21 Correct 256 ms 22916 KB Output is correct
22 Correct 264 ms 22916 KB Output is correct
23 Correct 262 ms 22920 KB Output is correct
24 Correct 258 ms 22928 KB Output is correct
25 Correct 109 ms 12940 KB Output is correct
26 Correct 100 ms 12940 KB Output is correct
27 Correct 262 ms 22952 KB Output is correct
28 Correct 262 ms 22996 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 11 ms 1384 KB Output is correct
37 Correct 293 ms 23004 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 14 ms 1408 KB Output is correct
41 Correct 260 ms 23056 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 6 ms 972 KB Output is correct
45 Correct 152 ms 13100 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 332 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 69 ms 6344 KB Output is correct
50 Correct 271 ms 23008 KB Output is correct
51 Correct 266 ms 22980 KB Output is correct
52 Correct 291 ms 23060 KB Output is correct
53 Correct 118 ms 13124 KB Output is correct
54 Correct 115 ms 13204 KB Output is correct
55 Correct 270 ms 22956 KB Output is correct
56 Correct 290 ms 22980 KB Output is correct
57 Correct 124 ms 13076 KB Output is correct
58 Correct 1 ms 332 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 66 ms 6328 KB Output is correct
62 Correct 267 ms 22948 KB Output is correct
63 Correct 267 ms 22948 KB Output is correct
64 Correct 254 ms 23008 KB Output is correct
65 Correct 1 ms 332 KB Output is correct
66 Correct 69 ms 6396 KB Output is correct
67 Correct 267 ms 22928 KB Output is correct
68 Correct 278 ms 23052 KB Output is correct
69 Correct 290 ms 23000 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 1 ms 332 KB Output is correct
72 Correct 1 ms 332 KB Output is correct
73 Correct 68 ms 6428 KB Output is correct
74 Correct 268 ms 23052 KB Output is correct
75 Correct 271 ms 22936 KB Output is correct
76 Correct 282 ms 22932 KB Output is correct
77 Correct 260 ms 23036 KB Output is correct
78 Correct 1 ms 332 KB Output is correct
79 Correct 1 ms 332 KB Output is correct
80 Correct 5 ms 972 KB Output is correct
81 Correct 105 ms 12944 KB Output is correct
82 Correct 1 ms 332 KB Output is correct
83 Correct 1 ms 332 KB Output is correct
84 Correct 1 ms 332 KB Output is correct
85 Correct 70 ms 6396 KB Output is correct
86 Correct 107 ms 13072 KB Output is correct
87 Correct 112 ms 12932 KB Output is correct
88 Correct 106 ms 13100 KB Output is correct
89 Correct 119 ms 13068 KB Output is correct
90 Correct 1 ms 332 KB Output is correct
91 Correct 1 ms 332 KB Output is correct
92 Correct 6 ms 992 KB Output is correct
93 Correct 97 ms 13100 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 1 ms 332 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 26 ms 3908 KB Output is correct
98 Correct 101 ms 14208 KB Output is correct
99 Correct 101 ms 14216 KB Output is correct
100 Correct 103 ms 14152 KB Output is correct
101 Correct 101 ms 14224 KB Output is correct
102 Correct 90 ms 14212 KB Output is correct
103 Correct 96 ms 14236 KB Output is correct
104 Correct 97 ms 14144 KB Output is correct
105 Correct 105 ms 14136 KB Output is correct