# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
362820 | mathking1021 | 슈퍼트리 잇기 (IOI20_supertrees) | C++17 | 1 ms | 512 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "supertrees.h"
#include <vector>
using namespace std;
int cp[1005];
int cp2[1005];
vector<int> ve[1005];
vector<int> ve2[1005];
vector<int> ve3;
int fnd(int p)
{
if(cp[p] == p) return p;
return cp[p] = fnd(cp[p]);
}
void uni(int p, int q)
{
if(fnd(p) == fnd(q)) return;
cp[fnd(p)] = fnd(q);
}
int fnd2(int p)
{
if(cp2[p] == p) return p;
return cp2[p] = fnd(cp2[p]);
}
void uni2(int p, int q)
{
if(fnd2(p) == fnd2(q)) return;
cp2[fnd2(p)] = fnd2(q);
}
int construct(vector<vector<int> > p) {
int n = p.size();
vector<vector<int> > answer;
for(int i = 0; i < n; i++)
{
cp[i] = i;
cp2[i] = i;
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(p[i][j]) uni(i, j);
}
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(!p[i][j] && fnd(i) == fnd(j)) return 0;
}
}
for(int i = 0; i < n; i++)
{
vector<int> row;
for(int j = 0; j < n; j++)
{
row.push_back(0);
}
answer.push_back(row);
}
for(int i = 0; i < n; i++)
{
ve[fnd(i)].push_back(i);
}
for(int i = 0; i < n; i++)
{
if(ve[i].size() == 0) continue;
if(ve[i].size() == 1) continue;
for(int j = 0; j < ve[i].size(); j++)
{
for(int k = j + 1; k < ve[i].size(); k++)
{
if(p[ve[i][j]][ve[i][k]] == 1) uni2(ve[i][j], ve[i][k]);
}
}
for(int j = 0; j < ve[i].size(); j++)
{
ve2[fnd2(ve[i][j])].push_back(ve[i][j]);
}
ve3.clear();
for(int j = 0; j < ve[i].size(); j++)
{
if(ve2[ve[i][j]].size() == 0) continue;
for(int k = 1; k < ve2[ve[i][j]].size(); k++)
{
answer[ve2[ve[i][j]][k]][ve2[ve[i][j]][k - 1]] = 1;
answer[ve2[ve[i][j]][k - 1]][ve2[ve[i][j]][k]] = 1;
}
ve3.push_back(ve[i][j]);
}
for(int j = 1; j < ve3.size(); j++)
{
answer[ve3[j]][ve3[j - 1]] = 1;
answer[ve3[j - 1]][ve3[j]] = 1;
}
answer[ve3[0]][ve3[ve3.size() - 1]] = 1;
answer[ve3[ve3.size() - 1]][ve3[0]] = 1;
}
build(answer);
return 1;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |