Submission #1114828

# Submission time Handle Problem Language Result Execution time Memory
1114828 2024-11-19T16:45:01 Z presko Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1 ms 504 KB
#include "supertrees.h"
#include <iostream>
#include <vector>
#include <algorithm>
#define MAXN 1010
using namespace std;
int parent[MAXN];
vector<pair<int,int>> used[MAXN];
bool done[MAXN];
int find(int curr)
{
    if(parent[curr]==curr)return curr;
    return parent[curr]=find(parent[curr]);
}
void unite(int a, int b, int t)
{
    a=find(a);
    b=find(b);
    if(a==b)return;
    if(used[a].size()<used[b].size())swap(a,b);
    parent[b]=a;
    used[a].push_back({t,b});
    for(int i=0;i<used[b].size();i++)used[a].push_back(used[b][i]);
}
int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> ans;
	for(int i=0;i<n;i++)
    {
        vector<int> dump(n,0);
        ans.push_back(dump);
        parent[i]=i;
        used[i]={{1,i}};
    }
	for (int i = 0; i < n; i++)
    {
		for(int j=0;j<n;j++)
		{
		    if(i==j)continue;
		    if(p[i][j]==1){unite(i,j,1);}
		    if(p[i][j]==2){unite(i,j,2);}
		}
	}
	for(int i=0;i<n;i++)
    {
        sort(used[i].begin(),used[i].end());
    }
	for(int i=0;i<n;i++)
    {
        int x=find(i);
        if(done[x])continue;
        for(int j=1;j<used[x].size();j++)
        {
            int val=used[x][j].second,t=used[x][j].first;
            if(t==0 || t==2 || used[x][j-1].first==0)continue;
            ans[used[x][j-1].second][val]=1;
            ans[val][used[x][j-1].second]=1;
        }
        for(int j=1;j<used[x].size();j++)
        {
            int val=used[x][j].second,t=used[x][j].first;
            if(t==0 || t==1)continue;
            if(used[x][j-1].first==1)
            {
                int left=used[x].size()-j;
                if(left==1)return 0;
                if(left==2)
                {
                    ans[used[x][j-1].second][val]=1;
                    ans[val][used[x][j-1].second]=1;
                    ans[used[x][j-1].second][used[x][j+1].second]=1;
                    ans[used[x][j+1].second][used[x][j-1].second]=1;
                }
                else
                {
                    ans[used[x][j-1].second][val]=1;
                    ans[val][used[x][j-1].second]=1;
                }
                continue;
            }
            ans[used[x][j-1].second][val]=1;
            ans[val][used[x][j-1].second]=1;
        }
        done[x]=1;
    }
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'void unite(int, int, int)':
supertrees.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0;i<used[b].size();i++)used[a].push_back(used[b][i]);
      |                 ~^~~~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int j=1;j<used[x].size();j++)
      |                     ~^~~~~~~~~~~~~~~
supertrees.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int j=1;j<used[x].size();j++)
      |                     ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB b[1][1] is not 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB b[1][1] is not 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Incorrect 1 ms 504 KB b[2][2] is not 0
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB b[2][2] is not 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB b[1][1] is not 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB b[1][1] is not 0
3 Halted 0 ms 0 KB -