Submission #849600

# Submission time Handle Problem Language Result Execution time Memory
849600 2023-09-15T04:41:29 Z abcvuitunggio Connecting Supertrees (IOI20_supertrees) C++17
100 / 100
194 ms 24144 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int n,l[1001];
vector <int> v,ve[1001];
vector <vector <int>> g;
int f(int u){
    return (l[u]<0?u:l[u]=f(l[u]));
}
bool unite(int u, int v){
    u=f(u);
    v=f(v);
    if (u==v)
        return false;
    if (l[u]<l[v])
        swap(u,v);
    l[u]+=l[v];
    l[v]=u;
    return true;
}
int construct(vector <vector <int>> p){
    n=p.size();
    g.resize(n);
    for (int i=0;i<n;i++)
        g[i].resize(n);
    memset(l,-1,sizeof(l));
	for (auto i:p)
        for (int j:i)
            if (j==3)
                return 0;
    for (int i=0;i<n;i++)
        for (int j=i+1;j<n;j++)
            if (p[i][j]==1)
                g[i][j]=g[j][i]=unite(i,j);
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if (f(i)==f(j)&&p[i][j]!=1)
                return 0;
    for (int i=0;i<n;i++)
        if (f(i)==i)
            v.push_back(i);
    memset(l,-1,sizeof(l));
    for (int i=0;i<n;i++)
        for (int j=i+1;j<n;j++)
            if (p[i][j]==2)
                unite(i,j);
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if (f(i)==f(j)&&!p[i][j])
                return 0;
    for (int i:v)
        ve[f(i)].push_back(i);
    for (int i=0;i<n;i++){
        if (ve[i].size()<=1)
            continue;
        if (ve[i].size()==2)
            return 0;
        for (int j=0;j<ve[i].size();j++){
            int u=ve[i][j],v=ve[i][(j+1)%ve[i].size()];
            g[u][v]=g[v][u]=1;
        }
    }
    build(g);
    return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for (int j=0;j<ve[i].size();j++){
      |                      ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1372 KB Output is correct
7 Correct 173 ms 23636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1372 KB Output is correct
7 Correct 173 ms 23636 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 6 ms 1196 KB Output is correct
13 Correct 149 ms 23428 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 964 KB Output is correct
17 Correct 70 ms 13396 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 47 ms 6316 KB Output is correct
21 Correct 154 ms 23376 KB Output is correct
22 Correct 153 ms 23380 KB Output is correct
23 Correct 159 ms 23464 KB Output is correct
24 Correct 161 ms 23380 KB Output is correct
25 Correct 65 ms 13396 KB Output is correct
26 Correct 67 ms 13332 KB Output is correct
27 Correct 163 ms 23896 KB Output is correct
28 Correct 157 ms 23520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 360 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 7 ms 1440 KB Output is correct
9 Correct 158 ms 24104 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1220 KB Output is correct
13 Correct 165 ms 24120 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 3 ms 960 KB Output is correct
17 Correct 76 ms 14244 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 500 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 39 ms 6488 KB Output is correct
22 Correct 156 ms 23988 KB Output is correct
23 Correct 156 ms 24100 KB Output is correct
24 Correct 169 ms 24084 KB Output is correct
25 Correct 81 ms 14100 KB Output is correct
26 Correct 66 ms 14232 KB Output is correct
27 Correct 194 ms 23960 KB Output is correct
28 Correct 163 ms 24144 KB Output is correct
29 Correct 65 ms 14240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 40 ms 6268 KB Output is correct
5 Correct 157 ms 23308 KB Output is correct
6 Correct 160 ms 23288 KB Output is correct
7 Correct 165 ms 23436 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 51 ms 6412 KB Output is correct
10 Correct 156 ms 23468 KB Output is correct
11 Correct 157 ms 23328 KB Output is correct
12 Correct 165 ms 23596 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 42 ms 6216 KB Output is correct
17 Correct 162 ms 23620 KB Output is correct
18 Correct 162 ms 23300 KB Output is correct
19 Correct 158 ms 23376 KB Output is correct
20 Correct 152 ms 23436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1372 KB Output is correct
7 Correct 173 ms 23636 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 6 ms 1196 KB Output is correct
13 Correct 149 ms 23428 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 964 KB Output is correct
17 Correct 70 ms 13396 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 47 ms 6316 KB Output is correct
21 Correct 154 ms 23376 KB Output is correct
22 Correct 153 ms 23380 KB Output is correct
23 Correct 159 ms 23464 KB Output is correct
24 Correct 161 ms 23380 KB Output is correct
25 Correct 65 ms 13396 KB Output is correct
26 Correct 67 ms 13332 KB Output is correct
27 Correct 163 ms 23896 KB Output is correct
28 Correct 157 ms 23520 KB Output is correct
29 Correct 1 ms 360 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 7 ms 1440 KB Output is correct
37 Correct 158 ms 24104 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 7 ms 1220 KB Output is correct
41 Correct 165 ms 24120 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 3 ms 960 KB Output is correct
45 Correct 76 ms 14244 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 500 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 39 ms 6488 KB Output is correct
50 Correct 156 ms 23988 KB Output is correct
51 Correct 156 ms 24100 KB Output is correct
52 Correct 169 ms 24084 KB Output is correct
53 Correct 81 ms 14100 KB Output is correct
54 Correct 66 ms 14232 KB Output is correct
55 Correct 194 ms 23960 KB Output is correct
56 Correct 163 ms 24144 KB Output is correct
57 Correct 65 ms 14240 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 4 ms 984 KB Output is correct
61 Correct 66 ms 14244 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 40 ms 6240 KB Output is correct
66 Correct 64 ms 14160 KB Output is correct
67 Correct 67 ms 14232 KB Output is correct
68 Correct 75 ms 14244 KB Output is correct
69 Correct 68 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 1372 KB Output is correct
7 Correct 173 ms 23636 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 6 ms 1196 KB Output is correct
13 Correct 149 ms 23428 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 964 KB Output is correct
17 Correct 70 ms 13396 KB Output is correct
18 Correct 1 ms 500 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 47 ms 6316 KB Output is correct
21 Correct 154 ms 23376 KB Output is correct
22 Correct 153 ms 23380 KB Output is correct
23 Correct 159 ms 23464 KB Output is correct
24 Correct 161 ms 23380 KB Output is correct
25 Correct 65 ms 13396 KB Output is correct
26 Correct 67 ms 13332 KB Output is correct
27 Correct 163 ms 23896 KB Output is correct
28 Correct 157 ms 23520 KB Output is correct
29 Correct 1 ms 360 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 7 ms 1440 KB Output is correct
37 Correct 158 ms 24104 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 7 ms 1220 KB Output is correct
41 Correct 165 ms 24120 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 3 ms 960 KB Output is correct
45 Correct 76 ms 14244 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 500 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 39 ms 6488 KB Output is correct
50 Correct 156 ms 23988 KB Output is correct
51 Correct 156 ms 24100 KB Output is correct
52 Correct 169 ms 24084 KB Output is correct
53 Correct 81 ms 14100 KB Output is correct
54 Correct 66 ms 14232 KB Output is correct
55 Correct 194 ms 23960 KB Output is correct
56 Correct 163 ms 24144 KB Output is correct
57 Correct 65 ms 14240 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 40 ms 6268 KB Output is correct
62 Correct 157 ms 23308 KB Output is correct
63 Correct 160 ms 23288 KB Output is correct
64 Correct 165 ms 23436 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 51 ms 6412 KB Output is correct
67 Correct 156 ms 23468 KB Output is correct
68 Correct 157 ms 23328 KB Output is correct
69 Correct 165 ms 23596 KB Output is correct
70 Correct 0 ms 344 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 42 ms 6216 KB Output is correct
74 Correct 162 ms 23620 KB Output is correct
75 Correct 162 ms 23300 KB Output is correct
76 Correct 158 ms 23376 KB Output is correct
77 Correct 152 ms 23436 KB Output is correct
78 Correct 1 ms 348 KB Output is correct
79 Correct 1 ms 348 KB Output is correct
80 Correct 4 ms 984 KB Output is correct
81 Correct 66 ms 14244 KB Output is correct
82 Correct 1 ms 344 KB Output is correct
83 Correct 1 ms 348 KB Output is correct
84 Correct 1 ms 344 KB Output is correct
85 Correct 40 ms 6240 KB Output is correct
86 Correct 64 ms 14160 KB Output is correct
87 Correct 67 ms 14232 KB Output is correct
88 Correct 75 ms 14244 KB Output is correct
89 Correct 68 ms 14160 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 3 ms 860 KB Output is correct
93 Correct 65 ms 14244 KB Output is correct
94 Correct 1 ms 344 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 1 ms 344 KB Output is correct
97 Correct 15 ms 3932 KB Output is correct
98 Correct 66 ms 14116 KB Output is correct
99 Correct 61 ms 14160 KB Output is correct
100 Correct 73 ms 14240 KB Output is correct
101 Correct 61 ms 14104 KB Output is correct
102 Correct 65 ms 14280 KB Output is correct
103 Correct 61 ms 14100 KB Output is correct
104 Correct 74 ms 14160 KB Output is correct
105 Correct 64 ms 14164 KB Output is correct