답안 #731286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
731286 2023-04-27T08:55:05 Z TheSahib 슈퍼트리 잇기 (IOI20_supertrees) C++14
0 / 100
1 ms 300 KB
#include "supertrees.h"
#include <bits/stdc++.h>

using namespace std;

const int MAX = 1005;
int par[MAX];

int find_set(int v){
    if(par[v] < 0) return v;
    return par[v] = find_set(par[v]);
}

bool unite(int u, int v){
    u = find_set(u);
    v = find_set(v);
    if(u == v) return false;

    par[u] += par[v];
    par[v] = u;
    return true;
}

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

    memset(par, -1, sizeof(par));
	for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if(p[i][j] == 1){
                unite(i, j);
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if(p[i][j] == 0 && find_set(i) == find_set(j)){
                return 0;
            }
        }
    }
    vector<int> v[MAX];
    for (int i = 0; i < n; i++)
    {
        v[find_set(i)].push_back(i);
    }
    for (int i = 0; i < n; i++)
    {
        for(int j = 0; j < v[i].size(); j++){
            if(j != 0){
                ans[v[i][j]] [v[i][j - 1]] = 1;
            }
            if(j != v[i].size() - 1){
                ans[v[i][j]] [v[i][j + 1]] = 1;
            }
        }
        if(v[i].size() > 1){
            ans[v[i][v[i].front()]] [v[i][v[i].back()]] = 1;
        }
    }
    
    build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:54:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for(int j = 0; j < v[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~
supertrees.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |             if(j != v[i].size() - 1){
      |                ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB b is not symmetric: b[0][2] (1) != b[2][0] (0)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB b is not symmetric: b[0][2] (1) != b[2][0] (0)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Too few ways to get from 0 to 1, should be 2 found 0
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB b is not symmetric: b[0][2] (1) != b[2][0] (0)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB b is not symmetric: b[0][2] (1) != b[2][0] (0)
4 Halted 0 ms 0 KB -