Submission #302070

#TimeUsernameProblemLanguageResultExecution timeMemory
302070radaiosm7슈퍼트리 잇기 (IOI20_supertrees)C++17
11 / 100
247 ms22188 KiB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;
int par[1005];
int depth[1005];
vector<int> teams[1005];

int FindPre(int x) {
  if (par[x] == x) {
    return x;
  }  else {
    par[x] = FindPre(par[x]);
    return par[x];
  }
}

bool IsSame(int x, int y) {
  if (FindPre(x) == FindPre(y)) {
    return true;
  }

  else {
    return false;
  }
}

void Union(int x, int y) {
  int PX = FindPre(x);
  int PY = FindPre(y);

  if (depth[PX] > depth[PY]) {
    par[PY] = PX;
  }

  else if (depth[PX] < depth[PY]) {
    par[PX] = PY;
  }

  else {
    par[PY] = PX;
    depth[PX]++;
  }
}


int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> ans(n, vector<int>(n, 0));

  for (int i=0; i < n; i++) {
    par[i] = i;
    depth[i] = 1;
  }

	for (int i=0; i < n-1; i++) {
    for (int j=i+1; j < n; j++) {
      if (p[i][j] == 1) {
        Union(i,j);
      }
    }
	}

  for (int i=0; i < n; i++) {
      teams[FindPre(i)].push_back(i);
  }

  for (int i=0; i < n-1; i++) {
    for (int j=i+1; j < n; j++) {
      if (p[i][j] == 0 && IsSame(i,j)) {
        printf("%d %d\n", i, j);
        return 0;
      }
    }
  }

  for (int i=0; i < n; i++) {
    for (int j=0; j < (int)teams[i].size()-1; j++) {
      ans[teams[i][j+1]][teams[i][j]] = 1;
      ans[teams[i][j]][teams[i][j+1]] = 1;
    }
  }

	build(ans);
	return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...