Submission #362820

# Submission time Handle Problem Language Result Execution time Memory
362820 2021-02-04T12:56:07 Z mathking1021 Connecting Supertrees (IOI20_supertrees) C++17
0 / 100
1 ms 512 KB
#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;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:75:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         for(int j = 0; j < ve[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~~
supertrees.cpp:77:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |             for(int k = j + 1; k < ve[i].size(); k++)
      |                                ~~^~~~~~~~~~~~~~
supertrees.cpp:82:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for(int j = 0; j < ve[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~~
supertrees.cpp:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         for(int j = 0; j < ve[i].size(); j++)
      |                        ~~^~~~~~~~~~~~~~
supertrees.cpp:90:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |             for(int k = 1; k < ve2[ve[i][j]].size(); k++)
      |                            ~~^~~~~~~~~~~~~~~~~~~~~~
supertrees.cpp:97:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |         for(int j = 1; j < ve3.size(); j++)
      |                        ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB b[1][1] is not 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB b[1][1] is not 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Incorrect 1 ms 396 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 0 ms 364 KB b[4][4] is not 0
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB b[1][1] is not 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB b[1][1] is not 0
3 Halted 0 ms 0 KB -