Submission #760582

# Submission time Handle Problem Language Result Execution time Memory
760582 2023-06-17T21:42:20 Z raysh07 Connecting Supertrees (IOI20_supertrees) C++17
11 / 100
164 ms 23972 KB
#include "supertrees.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const int N = 1001;
int root[N];
vector <int> adj[N];
bool vis[N];
vector <int> comp;

int find(int x){
    if (root[x] == x) return x;
    return root[x] = find(root[x]);
}

void unite(int x, int y){
    x = find(x); y = find(y);
    
    if (x == y) return;
    root[x] = y;
}

void dfs(int u){
    vis[u] = true;
    comp.push_back(u);
    
    for (auto v : adj[u]){
        if (!vis[v]) dfs(v);
    }
}

int construct(vector<vector<int>> p) {
	int n = p.size();
	vector<vector<int>> ans(n, vector<int>(n, 0));
	
	for (int i = 0; i < n; i++) root[i] = i;
	
	for (int i = 0; i < n; i++){
	    for (int j = i + 1; j < n; j++){
	        if (p[i][j] == 1) unite(i, j);
	        if (p[i][j] == 3) return 0;
	    }
	}
	
	for (int i = 0; i < n; i++){
	    if (find(i) != i){
	        ans[i][find(i)] = ans[find(i)][i] = 1;
	    }
	}
	
	for (int i = 0; i < n; i++){
	    for (int j = i + 1; j < n; j++){
	        if (p[i][j] == 2 && find(i) == i && find(j) == j) {
	            adj[i].push_back(j);
	            adj[j].push_back(i);
	        }
	    }
	}
	
	for (int i = 0; i < n; i++){
	    if (vis[i] || find(i) != i) continue;
	    
	    comp.clear();
	    dfs(i);
	    
	    if (comp.size() == 2) return 0;
	    
	    for (int j = 0; j < comp.size() - 1; j++){
	        ans[comp[j]][comp[j + 1]] = ans[comp[j + 1]][comp[j]] = 1;
	    }
	}
	build(ans);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:69:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |      for (int j = 0; j < comp.size() - 1; j++){
      |                      ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 164 ms 23960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 164 ms 23960 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 154 ms 23972 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 0 ms 328 KB Too few ways to get from 0 to 1, should be 2 found 1
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 164 ms 23960 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 154 ms 23972 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 164 ms 23960 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 7 ms 1236 KB Output is correct
13 Correct 154 ms 23972 KB Output is correct
14 Incorrect 1 ms 212 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -