Submission #301874

# Submission time Handle Problem Language Result Execution time Memory
301874 2020-09-18T09:03:56 Z SOIVIEONE Connecting Supertrees (IOI20_supertrees) C++14
100 / 100
294 ms 27512 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

int ota[222222], bobo[222222];
int find(int x)
{
    return (ota[x] == x ? x : ota[x] = find(ota[x]));
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    ota[y] = x;
}

int find2(int x)
{
    return (bobo[x] == x ? x : bobo[x] = find2(bobo[x]));
}
vector<int> v[222222];
void unite2(int x, int y)
{
    x = find2(x);
    y = find2(y);
    bobo[y] = x;
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> a;
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
		a.push_back(row);
	}
	for(int i = 0; i < n; i ++)
        ota[i] = i;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j ++)
        {
            if(p[i][j] == 1)
            {
                unite(i, j);
            }
        }
    }
    for(int i = 0; i < n; i ++)
        bobo[i] = ota[i];
    for(int i = 0; i < n; i ++)
    {
        for(int j = 0; j < n; j ++)
        {
            int foo = find(i), hoo = find(j);
            if(p[i][j] == 2)
            {
                unite2(foo, hoo);
            }
        }
    }
    for(int i = 0; i < n; i ++)
    for(int j = 0; j < n; j ++)
    {
        if(p[i][j] == 3)
            return 0;
        int boboi = find2(i), boboj = find2(j);
        int otai = find(i), otaj = find(j);

        if(otai == otaj)
        {
            if(p[i][j] != 1)
                return 0;
        }
        if(otai != otaj)
        {
            if(boboi == boboj)
            {
                if(p[i][j] != 2)
                    return 0;
            }
            else{
                if(p[i][j] != 0)
                    return 0;
            }
        }
        //if(boboi != boboj && p[i][j] != 2)
          //  return 0;
        if(otai == otaj)
        {
            if(otai != i)
                a[i][otai] = a[otai][i] = 1;
        }
    }
    vector<int> dead(n + 1, 0);
    set<int> s;
    for(int i = 0; i < n; i ++)
    {
        int o = find(i);

        if(dead[o])
            continue;
        dead[o] = 1;
        v[bobo[o]].push_back(o);
    }

    for(int i = 0; i <= n; i ++)
    {
        vector<int> it = v[i];
        if(it.size()==2)
            return 0;
        if(it.empty() || it.size() == 1)
            continue;
        //for(auto id : it)
            //cerr << id << ' ';
    //cerr << '\n';
        for(int j = 1; j < it.size(); j ++)
        {
            a[it[j]][it[j-1]] = a[it[j-1]][it[j]] = 1;
        }
        a[it.back()][it[0]] = a[it[0]][it.back()]=1;
    }
	build(a);
	return 1;
}
/*
5
1 0 0 1 1
0 1 1 0 0
0 1 1 0 0
1 0 0 1 1
1 0 0 1 1
*/

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:119:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |         for(int j = 1; j < it.size(); j ++)
      |                        ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5504 KB Output is correct
2 Correct 5 ms 5504 KB Output is correct
3 Correct 5 ms 5504 KB Output is correct
4 Correct 7 ms 5504 KB Output is correct
5 Correct 4 ms 5504 KB Output is correct
6 Correct 15 ms 6400 KB Output is correct
7 Correct 294 ms 27384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5504 KB Output is correct
2 Correct 5 ms 5504 KB Output is correct
3 Correct 5 ms 5504 KB Output is correct
4 Correct 7 ms 5504 KB Output is correct
5 Correct 4 ms 5504 KB Output is correct
6 Correct 15 ms 6400 KB Output is correct
7 Correct 294 ms 27384 KB Output is correct
8 Correct 4 ms 5504 KB Output is correct
9 Correct 5 ms 5504 KB Output is correct
10 Correct 4 ms 5536 KB Output is correct
11 Correct 4 ms 5504 KB Output is correct
12 Correct 16 ms 6400 KB Output is correct
13 Correct 257 ms 27344 KB Output is correct
14 Correct 4 ms 5504 KB Output is correct
15 Correct 5 ms 5504 KB Output is correct
16 Correct 10 ms 6144 KB Output is correct
17 Correct 125 ms 17400 KB Output is correct
18 Correct 4 ms 5504 KB Output is correct
19 Correct 4 ms 5608 KB Output is correct
20 Correct 103 ms 11128 KB Output is correct
21 Correct 281 ms 27384 KB Output is correct
22 Correct 255 ms 27384 KB Output is correct
23 Correct 282 ms 27384 KB Output is correct
24 Correct 247 ms 27384 KB Output is correct
25 Correct 108 ms 17400 KB Output is correct
26 Correct 111 ms 17400 KB Output is correct
27 Correct 279 ms 27384 KB Output is correct
28 Correct 248 ms 27460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5504 KB Output is correct
2 Correct 4 ms 5504 KB Output is correct
3 Correct 4 ms 5504 KB Output is correct
4 Correct 4 ms 5504 KB Output is correct
5 Correct 4 ms 5504 KB Output is correct
6 Correct 4 ms 5504 KB Output is correct
7 Correct 4 ms 5504 KB Output is correct
8 Correct 14 ms 6400 KB Output is correct
9 Correct 247 ms 27512 KB Output is correct
10 Correct 4 ms 5504 KB Output is correct
11 Correct 4 ms 5504 KB Output is correct
12 Correct 15 ms 6400 KB Output is correct
13 Correct 261 ms 27384 KB Output is correct
14 Correct 4 ms 5504 KB Output is correct
15 Correct 4 ms 5504 KB Output is correct
16 Correct 9 ms 6068 KB Output is correct
17 Correct 120 ms 17400 KB Output is correct
18 Correct 4 ms 5632 KB Output is correct
19 Correct 4 ms 5504 KB Output is correct
20 Correct 4 ms 5536 KB Output is correct
21 Correct 67 ms 11000 KB Output is correct
22 Correct 262 ms 27336 KB Output is correct
23 Correct 249 ms 27324 KB Output is correct
24 Correct 268 ms 27384 KB Output is correct
25 Correct 109 ms 17400 KB Output is correct
26 Correct 103 ms 17400 KB Output is correct
27 Correct 249 ms 27332 KB Output is correct
28 Correct 279 ms 27384 KB Output is correct
29 Correct 105 ms 17400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5504 KB Output is correct
2 Correct 4 ms 5632 KB Output is correct
3 Correct 4 ms 5504 KB Output is correct
4 Correct 66 ms 11128 KB Output is correct
5 Correct 258 ms 27456 KB Output is correct
6 Correct 252 ms 27384 KB Output is correct
7 Correct 269 ms 27384 KB Output is correct
8 Correct 4 ms 5504 KB Output is correct
9 Correct 66 ms 11000 KB Output is correct
10 Correct 251 ms 27332 KB Output is correct
11 Correct 254 ms 27384 KB Output is correct
12 Correct 267 ms 27500 KB Output is correct
13 Correct 4 ms 5504 KB Output is correct
14 Correct 5 ms 5504 KB Output is correct
15 Correct 4 ms 5504 KB Output is correct
16 Correct 66 ms 11000 KB Output is correct
17 Correct 263 ms 27384 KB Output is correct
18 Correct 274 ms 27384 KB Output is correct
19 Correct 274 ms 27384 KB Output is correct
20 Correct 275 ms 27384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5504 KB Output is correct
2 Correct 5 ms 5504 KB Output is correct
3 Correct 5 ms 5504 KB Output is correct
4 Correct 7 ms 5504 KB Output is correct
5 Correct 4 ms 5504 KB Output is correct
6 Correct 15 ms 6400 KB Output is correct
7 Correct 294 ms 27384 KB Output is correct
8 Correct 4 ms 5504 KB Output is correct
9 Correct 5 ms 5504 KB Output is correct
10 Correct 4 ms 5536 KB Output is correct
11 Correct 4 ms 5504 KB Output is correct
12 Correct 16 ms 6400 KB Output is correct
13 Correct 257 ms 27344 KB Output is correct
14 Correct 4 ms 5504 KB Output is correct
15 Correct 5 ms 5504 KB Output is correct
16 Correct 10 ms 6144 KB Output is correct
17 Correct 125 ms 17400 KB Output is correct
18 Correct 4 ms 5504 KB Output is correct
19 Correct 4 ms 5608 KB Output is correct
20 Correct 103 ms 11128 KB Output is correct
21 Correct 281 ms 27384 KB Output is correct
22 Correct 255 ms 27384 KB Output is correct
23 Correct 282 ms 27384 KB Output is correct
24 Correct 247 ms 27384 KB Output is correct
25 Correct 108 ms 17400 KB Output is correct
26 Correct 111 ms 17400 KB Output is correct
27 Correct 279 ms 27384 KB Output is correct
28 Correct 248 ms 27460 KB Output is correct
29 Correct 4 ms 5504 KB Output is correct
30 Correct 4 ms 5504 KB Output is correct
31 Correct 4 ms 5504 KB Output is correct
32 Correct 4 ms 5504 KB Output is correct
33 Correct 4 ms 5504 KB Output is correct
34 Correct 4 ms 5504 KB Output is correct
35 Correct 4 ms 5504 KB Output is correct
36 Correct 14 ms 6400 KB Output is correct
37 Correct 247 ms 27512 KB Output is correct
38 Correct 4 ms 5504 KB Output is correct
39 Correct 4 ms 5504 KB Output is correct
40 Correct 15 ms 6400 KB Output is correct
41 Correct 261 ms 27384 KB Output is correct
42 Correct 4 ms 5504 KB Output is correct
43 Correct 4 ms 5504 KB Output is correct
44 Correct 9 ms 6068 KB Output is correct
45 Correct 120 ms 17400 KB Output is correct
46 Correct 4 ms 5632 KB Output is correct
47 Correct 4 ms 5504 KB Output is correct
48 Correct 4 ms 5536 KB Output is correct
49 Correct 67 ms 11000 KB Output is correct
50 Correct 262 ms 27336 KB Output is correct
51 Correct 249 ms 27324 KB Output is correct
52 Correct 268 ms 27384 KB Output is correct
53 Correct 109 ms 17400 KB Output is correct
54 Correct 103 ms 17400 KB Output is correct
55 Correct 249 ms 27332 KB Output is correct
56 Correct 279 ms 27384 KB Output is correct
57 Correct 105 ms 17400 KB Output is correct
58 Correct 5 ms 5504 KB Output is correct
59 Correct 4 ms 5504 KB Output is correct
60 Correct 9 ms 6016 KB Output is correct
61 Correct 131 ms 17348 KB Output is correct
62 Correct 5 ms 5504 KB Output is correct
63 Correct 4 ms 5504 KB Output is correct
64 Correct 4 ms 5504 KB Output is correct
65 Correct 67 ms 11000 KB Output is correct
66 Correct 112 ms 17400 KB Output is correct
67 Correct 116 ms 17400 KB Output is correct
68 Correct 108 ms 17400 KB Output is correct
69 Correct 114 ms 17528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5504 KB Output is correct
2 Correct 5 ms 5504 KB Output is correct
3 Correct 5 ms 5504 KB Output is correct
4 Correct 7 ms 5504 KB Output is correct
5 Correct 4 ms 5504 KB Output is correct
6 Correct 15 ms 6400 KB Output is correct
7 Correct 294 ms 27384 KB Output is correct
8 Correct 4 ms 5504 KB Output is correct
9 Correct 5 ms 5504 KB Output is correct
10 Correct 4 ms 5536 KB Output is correct
11 Correct 4 ms 5504 KB Output is correct
12 Correct 16 ms 6400 KB Output is correct
13 Correct 257 ms 27344 KB Output is correct
14 Correct 4 ms 5504 KB Output is correct
15 Correct 5 ms 5504 KB Output is correct
16 Correct 10 ms 6144 KB Output is correct
17 Correct 125 ms 17400 KB Output is correct
18 Correct 4 ms 5504 KB Output is correct
19 Correct 4 ms 5608 KB Output is correct
20 Correct 103 ms 11128 KB Output is correct
21 Correct 281 ms 27384 KB Output is correct
22 Correct 255 ms 27384 KB Output is correct
23 Correct 282 ms 27384 KB Output is correct
24 Correct 247 ms 27384 KB Output is correct
25 Correct 108 ms 17400 KB Output is correct
26 Correct 111 ms 17400 KB Output is correct
27 Correct 279 ms 27384 KB Output is correct
28 Correct 248 ms 27460 KB Output is correct
29 Correct 4 ms 5504 KB Output is correct
30 Correct 4 ms 5504 KB Output is correct
31 Correct 4 ms 5504 KB Output is correct
32 Correct 4 ms 5504 KB Output is correct
33 Correct 4 ms 5504 KB Output is correct
34 Correct 4 ms 5504 KB Output is correct
35 Correct 4 ms 5504 KB Output is correct
36 Correct 14 ms 6400 KB Output is correct
37 Correct 247 ms 27512 KB Output is correct
38 Correct 4 ms 5504 KB Output is correct
39 Correct 4 ms 5504 KB Output is correct
40 Correct 15 ms 6400 KB Output is correct
41 Correct 261 ms 27384 KB Output is correct
42 Correct 4 ms 5504 KB Output is correct
43 Correct 4 ms 5504 KB Output is correct
44 Correct 9 ms 6068 KB Output is correct
45 Correct 120 ms 17400 KB Output is correct
46 Correct 4 ms 5632 KB Output is correct
47 Correct 4 ms 5504 KB Output is correct
48 Correct 4 ms 5536 KB Output is correct
49 Correct 67 ms 11000 KB Output is correct
50 Correct 262 ms 27336 KB Output is correct
51 Correct 249 ms 27324 KB Output is correct
52 Correct 268 ms 27384 KB Output is correct
53 Correct 109 ms 17400 KB Output is correct
54 Correct 103 ms 17400 KB Output is correct
55 Correct 249 ms 27332 KB Output is correct
56 Correct 279 ms 27384 KB Output is correct
57 Correct 105 ms 17400 KB Output is correct
58 Correct 4 ms 5504 KB Output is correct
59 Correct 4 ms 5632 KB Output is correct
60 Correct 4 ms 5504 KB Output is correct
61 Correct 66 ms 11128 KB Output is correct
62 Correct 258 ms 27456 KB Output is correct
63 Correct 252 ms 27384 KB Output is correct
64 Correct 269 ms 27384 KB Output is correct
65 Correct 4 ms 5504 KB Output is correct
66 Correct 66 ms 11000 KB Output is correct
67 Correct 251 ms 27332 KB Output is correct
68 Correct 254 ms 27384 KB Output is correct
69 Correct 267 ms 27500 KB Output is correct
70 Correct 4 ms 5504 KB Output is correct
71 Correct 5 ms 5504 KB Output is correct
72 Correct 4 ms 5504 KB Output is correct
73 Correct 66 ms 11000 KB Output is correct
74 Correct 263 ms 27384 KB Output is correct
75 Correct 274 ms 27384 KB Output is correct
76 Correct 274 ms 27384 KB Output is correct
77 Correct 275 ms 27384 KB Output is correct
78 Correct 5 ms 5504 KB Output is correct
79 Correct 4 ms 5504 KB Output is correct
80 Correct 9 ms 6016 KB Output is correct
81 Correct 131 ms 17348 KB Output is correct
82 Correct 5 ms 5504 KB Output is correct
83 Correct 4 ms 5504 KB Output is correct
84 Correct 4 ms 5504 KB Output is correct
85 Correct 67 ms 11000 KB Output is correct
86 Correct 112 ms 17400 KB Output is correct
87 Correct 116 ms 17400 KB Output is correct
88 Correct 108 ms 17400 KB Output is correct
89 Correct 114 ms 17528 KB Output is correct
90 Correct 4 ms 5504 KB Output is correct
91 Correct 4 ms 5536 KB Output is correct
92 Correct 9 ms 5992 KB Output is correct
93 Correct 119 ms 17404 KB Output is correct
94 Correct 4 ms 5504 KB Output is correct
95 Correct 4 ms 5504 KB Output is correct
96 Correct 4 ms 5504 KB Output is correct
97 Correct 45 ms 8568 KB Output is correct
98 Correct 108 ms 17400 KB Output is correct
99 Correct 117 ms 17436 KB Output is correct
100 Correct 109 ms 17400 KB Output is correct
101 Correct 158 ms 17308 KB Output is correct
102 Correct 102 ms 17400 KB Output is correct
103 Correct 113 ms 17400 KB Output is correct
104 Correct 118 ms 17400 KB Output is correct
105 Correct 107 ms 17400 KB Output is correct