Submission #839281

# Submission time Handle Problem Language Result Execution time Memory
839281 2023-08-29T14:00:47 Z epicci23 Connecting Supertrees (IOI20_supertrees) C++17
96 / 100
182 ms 22772 KB
#include "supertrees.h"
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define endl "\n" 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()


const int N = 1005;

int par[N];
int siz[N];

int find(int a)
{
  if(par[a]==a) return a;
  return par[a]=find(par[a]);
}

void unite(int a,int b)
{
  a=find(a),b=find(b);
  if(a==b) return;
  if(siz[a]>siz[b]) swap(a,b);
  siz[b]+=siz[a];
  par[a]=b;
}

int construct(vector<vector<int>> p) {
  iota(par,par+N,0LL);
  fill(siz,siz+N,1LL);
    
    int n = p[0].size();
    vector<vector<int>> g(n,vector<int>(n,0));
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        if(p[i][j]) unite(i,j);
    
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        if(!p[i][j] && find(i)==find(j))
          return 0;
        

    vector<int> no[n];
    for(int i=0;i<n;i++) no[find(i)].pb(i);

    for(int xd=0;xd<n;xd++)
    {
      if(no[xd].size()<=1) continue;
      int m = no[xd].size();
      vector<int> v[m];
      for(int i=0;i<m;i++)
      {
        for(int j=i;j<m;j++)
        {
          if(i==j)
          {
            v[i].pb(i);
            continue;
          }
          int a=no[xd][i];
          int b=no[xd][j];
          if(p[a][b]==1)
          {
            v[i].pb(j);
            v[j].pb(i);
          }
        }
      }
      for(int i=0;i<m;i++) sort(all(v[i]));
      vector<int> tems;
      vector<int> vis(m,0LL); 
      for(int i=0;i<m;i++)
      {
       if(vis[i]) continue;
       tems.pb(i);
       for(int x:v[i])
       {
        if(vis[x]) return 0;
        vis[x]=1; 
        if(v[i]!=v[x]) return 0;
       }
       for(int j=1;j<sz(v[i]);j++)
       {
        int a=no[xd][v[i][j]];
        int b=no[xd][v[i][j-1]];
        g[a][b]=g[b][a]=1;
       }
      }

      int k=sz(tems);
      if(k==2) return 0;
      if(k>2)
      {
       for(int i=1;i<k;i++)
       { 
        g[no[xd][tems[i]]][no[xd][tems[i-1]]]=1;
        g[no[xd][tems[i-1]]][no[xd][tems[i]]]=1;
       } 
       g[no[xd][tems[k-1]]][no[xd][tems[0]]]=1;
       g[no[xd][tems[0]]][no[xd][tems[k-1]]]=1;
      }
    }
  build(g);
  return 1;
}
	
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1236 KB Output is correct
7 Correct 182 ms 22768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1236 KB Output is correct
7 Correct 182 ms 22768 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 151 ms 22716 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 12676 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 39 ms 6204 KB Output is correct
21 Correct 154 ms 22772 KB Output is correct
22 Correct 148 ms 22728 KB Output is correct
23 Correct 158 ms 22672 KB Output is correct
24 Correct 149 ms 22720 KB Output is correct
25 Correct 61 ms 12680 KB Output is correct
26 Correct 62 ms 12676 KB Output is correct
27 Correct 159 ms 22736 KB Output is correct
28 Correct 146 ms 22636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 7 ms 1364 KB Output is correct
9 Correct 148 ms 22668 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 151 ms 22736 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 71 ms 12876 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 38 ms 6220 KB Output is correct
22 Correct 150 ms 22732 KB Output is correct
23 Correct 152 ms 22692 KB Output is correct
24 Correct 158 ms 22692 KB Output is correct
25 Correct 65 ms 12792 KB Output is correct
26 Correct 63 ms 12748 KB Output is correct
27 Correct 151 ms 22676 KB Output is correct
28 Correct 152 ms 22688 KB Output is correct
29 Correct 62 ms 12780 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 1 ms 212 KB Output is correct
4 Correct 45 ms 6364 KB Output is correct
5 Correct 151 ms 22732 KB Output is correct
6 Correct 152 ms 22700 KB Output is correct
7 Correct 158 ms 22736 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 37 ms 6188 KB Output is correct
10 Correct 148 ms 22624 KB Output is correct
11 Correct 154 ms 22624 KB Output is correct
12 Correct 164 ms 22772 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 38 ms 6220 KB Output is correct
17 Correct 148 ms 22764 KB Output is correct
18 Correct 161 ms 22632 KB Output is correct
19 Correct 150 ms 22700 KB Output is correct
20 Correct 148 ms 22676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1236 KB Output is correct
7 Correct 182 ms 22768 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 151 ms 22716 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 12676 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 39 ms 6204 KB Output is correct
21 Correct 154 ms 22772 KB Output is correct
22 Correct 148 ms 22728 KB Output is correct
23 Correct 158 ms 22672 KB Output is correct
24 Correct 149 ms 22720 KB Output is correct
25 Correct 61 ms 12680 KB Output is correct
26 Correct 62 ms 12676 KB Output is correct
27 Correct 159 ms 22736 KB Output is correct
28 Correct 146 ms 22636 KB Output is correct
29 Correct 1 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 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1364 KB Output is correct
37 Correct 148 ms 22668 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 6 ms 1236 KB Output is correct
41 Correct 151 ms 22736 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 71 ms 12876 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 38 ms 6220 KB Output is correct
50 Correct 150 ms 22732 KB Output is correct
51 Correct 152 ms 22692 KB Output is correct
52 Correct 158 ms 22692 KB Output is correct
53 Correct 65 ms 12792 KB Output is correct
54 Correct 63 ms 12748 KB Output is correct
55 Correct 151 ms 22676 KB Output is correct
56 Correct 152 ms 22688 KB Output is correct
57 Correct 62 ms 12780 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 852 KB Output is correct
61 Correct 69 ms 13156 KB Output is correct
62 Correct 1 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 37 ms 6220 KB Output is correct
66 Correct 61 ms 13132 KB Output is correct
67 Correct 62 ms 13096 KB Output is correct
68 Correct 60 ms 13132 KB Output is correct
69 Correct 64 ms 13096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 1236 KB Output is correct
7 Correct 182 ms 22768 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 6 ms 1236 KB Output is correct
13 Correct 151 ms 22716 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 70 ms 12676 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 39 ms 6204 KB Output is correct
21 Correct 154 ms 22772 KB Output is correct
22 Correct 148 ms 22728 KB Output is correct
23 Correct 158 ms 22672 KB Output is correct
24 Correct 149 ms 22720 KB Output is correct
25 Correct 61 ms 12680 KB Output is correct
26 Correct 62 ms 12676 KB Output is correct
27 Correct 159 ms 22736 KB Output is correct
28 Correct 146 ms 22636 KB Output is correct
29 Correct 1 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 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 7 ms 1364 KB Output is correct
37 Correct 148 ms 22668 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 6 ms 1236 KB Output is correct
41 Correct 151 ms 22736 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 3 ms 852 KB Output is correct
45 Correct 71 ms 12876 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 38 ms 6220 KB Output is correct
50 Correct 150 ms 22732 KB Output is correct
51 Correct 152 ms 22692 KB Output is correct
52 Correct 158 ms 22692 KB Output is correct
53 Correct 65 ms 12792 KB Output is correct
54 Correct 63 ms 12748 KB Output is correct
55 Correct 151 ms 22676 KB Output is correct
56 Correct 152 ms 22688 KB Output is correct
57 Correct 62 ms 12780 KB Output is correct
58 Correct 0 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 45 ms 6364 KB Output is correct
62 Correct 151 ms 22732 KB Output is correct
63 Correct 152 ms 22700 KB Output is correct
64 Correct 158 ms 22736 KB Output is correct
65 Correct 1 ms 212 KB Output is correct
66 Correct 37 ms 6188 KB Output is correct
67 Correct 148 ms 22624 KB Output is correct
68 Correct 154 ms 22624 KB Output is correct
69 Correct 164 ms 22772 KB Output is correct
70 Correct 1 ms 336 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 38 ms 6220 KB Output is correct
74 Correct 148 ms 22764 KB Output is correct
75 Correct 161 ms 22632 KB Output is correct
76 Correct 150 ms 22700 KB Output is correct
77 Correct 148 ms 22676 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 852 KB Output is correct
81 Correct 69 ms 13156 KB Output is correct
82 Correct 1 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 37 ms 6220 KB Output is correct
86 Correct 61 ms 13132 KB Output is correct
87 Correct 62 ms 13096 KB Output is correct
88 Correct 60 ms 13132 KB Output is correct
89 Correct 64 ms 13096 KB Output is correct
90 Correct 1 ms 212 KB Output is correct
91 Correct 1 ms 304 KB Output is correct
92 Correct 3 ms 852 KB Output is correct
93 Correct 78 ms 13092 KB Output is correct
94 Incorrect 1 ms 336 KB Answer gives possible 1 while actual possible 0
95 Halted 0 ms 0 KB -