Submission #867058

# Submission time Handle Problem Language Result Execution time Memory
867058 2023-10-27T15:45:07 Z Ninedesu Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1 ms 604 KB
#include "supertrees.h"
#include<bits/stdc++.h>
using namespace std;

const int N=1001;
int pa1[N],pa2[N],compo1[N],compo2[N];
bool vis1[N],vis2[N],chk1,chk2,chk;
vector<int>adj1[N],adj2[N],root1,root2;

int dsu1(int x){
	if(pa1[x]==x)return x;
	else return pa1[x]=dsu1(pa1[x]);
}

int dsu2(int x){
    if(pa2[x]==x)return x;
    else return pa2[x]=dsu2(pa2[x]);
}

int construct(vector<vector<int>> p) {
	int n=p.size();
	vector<vector<int>> answer;
	for (int i = 0; i < n; i++) {
		vector<int> row;
		row.resize(n);
		answer.push_back(row);
		for(int j=0; j<n; j++){
			if(p[i][j]==3)return 0;
		}
		pa1[i]=i;
		pa2[i]=i;
	}
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(p[i][j])chk=true;
			if(p[i][j]==1)pa1[dsu1(j)]=dsu1(i);
		}
	}
	if(!chk){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				answer[i][j]=0;
			}
		}
		build(answer);
		return 1;
	}
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i!=j&&dsu1(i)==dsu1(j)){
                if(p[i][j]==0||p[i][j]==2){
                    return 0;
                }
                adj1[i].push_back(j);
                adj1[j].push_back(i);
            }
        }
    }
    for(int i=0; i<n; i++){
        if(vis1[i])continue;
        root1.push_back(i);
        compo1[i]=i;
        for(int j:adj1[i]){
            compo1[j]=i;
            vis1[j]=true;
            answer[i][j]=1;
            answer[j][i]=1;
        }
    }
    for(int i=0; i<root1.size(); i++){
        for(int j=i+1; j<root1.size(); j++){
            int a=root1[i],b=root1[j];
            if(p[a][b]==2)pa2[dsu2(a)]=dsu2(b);
        }
    }
    for(int i:root1){
        for(int j:root1){
            if(i!=j&&dsu2(i)==dsu2(j)){
                if(p[i][j]==0||p[i][j]==1){
                    return 0;
                }
                adj2[i].push_back(j);
                adj2[j].push_back(i);
            }
        }
    }
    for(int i:root1){
        if(vis2[i])continue;
        root2.push_back(i);
        compo2[i]=i;
        for(int j:adj2[i]){
            compo2[j]=i;
            vis2[j]=true;
        }
    }
    for(int i:root2){
        for(int j=1; j<adj2[i].size(); j++){
            answer[adj2[i][j]][adj2[i][j-1]]=1;
            answer[adj2[i][j-1]][adj2[i][j]]=1;
        }
        answer[adj2[i][0]][i]=1;
        answer[i][adj2[i][0]]=1;
        answer[adj2[i][adj2[i].size()-1]][i]=1;
        answer[i][adj2[i][adj2[i].size()-1]]=1;
    }

	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:70:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i=0; i<root1.size(); i++){
      |                  ~^~~~~~~~~~~~~
supertrees.cpp:71:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int j=i+1; j<root1.size(); j++){
      |                        ~^~~~~~~~~~~~~
supertrees.cpp:97:23: 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<adj2[i].size(); j++){
      |                      ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 600 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 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Runtime error 1 ms 464 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -