Submission #937765

# Submission time Handle Problem Language Result Execution time Memory
937765 2024-03-04T12:44:38 Z Hugo1729 Connecting Supertrees (IOI20_supertrees) C++17
21 / 100
183 ms 23452 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

struct DSU{
int n;
vector<int> e;

DSU(int s){
  n=s;e.assign(n,-1);
}
int find(int v){
  return (e[v]<0?v:e[v]=find(e[v]));
}
bool same(int a, int b){
  return find(a)==find(b);
}
bool connect(int a, int b){
  a=find(a);b=find(b);
  if(a==b)return 0;
  if(e[a]>e[b])swap(a,b);
  e[a]+=e[b];
  e[b]=a;
  return 1;
}
};

int construct(vector<vector<int>> p) {
  int n = p.size();
  DSU groups(n),rep(n);
  vector<vector<int>> answer;
  for (int i = 0; i < n; i++){
    for(int j=0;j<n;j++){
      if(j!=i){
        if(p[i][j]==0){
          if(groups.same(i,j))return 0;
        }else if(p[i][j]==1){
          if(!rep.same(i,j)){
            bool flag=1;
            for(int k=0;k<n;k++){
              if(p[i][k]!=p[j][k]){
                flag=0;
              }
            }
            if(flag){
              rep.connect(i,j);
              groups.connect(i,j);
            } else{
              return 0;
            }
          }
        } else if(p[i][j]==2){
          if(rep.same(i,j))return 0;
          groups.connect(i,j);
        }
      }
    }
    vector<int> row;
    row.assign(n,0);
    answer.push_back(row);
  }

  vector<vector<int>> circles;
  int t=0;
  map<int,int> mcircles;
  for(int i=0;i<n;i++){
    if(rep.e[i]<0){
      if(mcircles.count(groups.find(i))==0){
        circles.push_back({rep.find(i)});
        mcircles[groups.find(i)]=t;
        t++;
      } else{
        circles[mcircles[groups.find(i)]].push_back(rep.find(i));
      }
    }else{
      if(rep.find(i)!=i){
        answer[i][rep.find(i)]=1;
        answer[rep.find(i)][i]=1;
      }
    }
  }

  // cout << "dsfasdfsdafsda";

  for(vector<int> h : circles){
    if(h.size()<=1)continue;
    if(h.size()==2)return 0;

    for(int j=0;j<h.size();j++){
      answer[h[j]][h[(j+1)%h.size()]]=1;
      answer[h[(j+1)%h.size()]][h[j]]=1;
      cout << h[j] << '\n';
    }
  }
  
  build(answer);
  return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:89:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for(int j=0;j<h.size();j++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 159 ms 23360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 159 ms 23360 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 159 ms 23436 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 676 KB Output is correct
17 Correct 60 ms 9588 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 39 ms 6224 KB Output is correct
21 Correct 157 ms 23352 KB Output is correct
22 Correct 157 ms 23376 KB Output is correct
23 Correct 176 ms 23348 KB Output is correct
24 Correct 164 ms 23380 KB Output is correct
25 Correct 58 ms 9556 KB Output is correct
26 Correct 56 ms 9620 KB Output is correct
27 Correct 165 ms 23376 KB Output is correct
28 Correct 183 ms 23452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 1 ms 348 KB secret mismatch
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB secret mismatch
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 159 ms 23360 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 159 ms 23436 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 676 KB Output is correct
17 Correct 60 ms 9588 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 39 ms 6224 KB Output is correct
21 Correct 157 ms 23352 KB Output is correct
22 Correct 157 ms 23376 KB Output is correct
23 Correct 176 ms 23348 KB Output is correct
24 Correct 164 ms 23380 KB Output is correct
25 Correct 58 ms 9556 KB Output is correct
26 Correct 56 ms 9620 KB Output is correct
27 Correct 165 ms 23376 KB Output is correct
28 Correct 183 ms 23452 KB Output is correct
29 Correct 0 ms 600 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Incorrect 1 ms 348 KB secret mismatch
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 436 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 432 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1372 KB Output is correct
7 Correct 159 ms 23360 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 159 ms 23436 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 676 KB Output is correct
17 Correct 60 ms 9588 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 39 ms 6224 KB Output is correct
21 Correct 157 ms 23352 KB Output is correct
22 Correct 157 ms 23376 KB Output is correct
23 Correct 176 ms 23348 KB Output is correct
24 Correct 164 ms 23380 KB Output is correct
25 Correct 58 ms 9556 KB Output is correct
26 Correct 56 ms 9620 KB Output is correct
27 Correct 165 ms 23376 KB Output is correct
28 Correct 183 ms 23452 KB Output is correct
29 Correct 0 ms 600 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Incorrect 1 ms 348 KB secret mismatch
34 Halted 0 ms 0 KB -