Submission #301777

#TimeUsernameProblemLanguageResultExecution timeMemory
301777Pro100YanConnecting Supertrees (IOI20_supertrees)C++14
0 / 100
1069 ms12408 KiB
#include "supertrees.h"
#include <vector>
#include <iostream>
#define ll long long
#define pb push_back
 
using namespace std;
const int N = 2005;
vector<int> gr[N];
int used[N], d[N], sz[N];
vector<vector<int>> ans;
 
int get_parent(int v){
    while(v != d[v])
        v = d[v];
    return v;
}
 
void add(int u, int v){
    //cout << "Add " << u << ' ' << v << endl;
    int f = get_parent(u), s = get_parent(v);
    //cout << "Parents " << f << ' ' << s << endl;
    if(f != s){
        ans[f][s] = ans[s][f] = 1;
       	d[f] = d[s];
    }
}
 
 
 
int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	int fault = 0;
	for(int i = 0; i < n; i++){
        d[i] = i;
        sz[i] = 1;
	}
	for(int i = 0; i < n; i++){
        ans.pb({});
        for(int j = 0; j < n; j++)
            ans[i].pb(0);
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(p[i][j] && i != j){
                add(i, j);
            }
        }
    }
  	for(int i = 0; i < n; i++){
     	for(int j = 0; j < n; j++){
         	int fp = get_parent(i);
          	int sp = get_parent(j);
          	if((fp == sp && p[i][j] == 0) || (fp != sp && p[i][j]))
             	return 0;
        }
    }
    /*for(int i = 0; i < n; i++){
        if(!used[i])
            dfs(i);
    }*/
	build(ans);
	return 1;
}
/*
5
1 0 0 1 1
0 1 1 0 0
0 1 1 0 0
1 0 0 1 1
1 0 0 1 1
*/

Compilation message (stderr)

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:33:6: warning: unused variable 'fault' [-Wunused-variable]
   33 |  int fault = 0;
      |      ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...