답안 #853582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853582 2023-09-24T17:03:01 Z ntkphong 슈퍼트리 잇기 (IOI20_supertrees) C++14
11 / 100
169 ms 24148 KB
#include "supertrees.h"
#include <bits/stdc++.h>
using namespace std;

vector<int> lab;

int get_root(int u) {
    return lab[u] == u ? u : lab[u] = get_root(lab[u]);
}

bool unite(int u, int v) {
    u = get_root(u);
    v = get_root(v);
    
    if(u == v) return false;
    lab[v] = u;
    
    return true;
}

int construct(vector<vector<int>> p) {
	int n = p.size();
    
    lab.resize(n);
    for(int i = 0; i < n; i ++) lab[i] = i;
    
    vector<int> mark(n, 0);
    vector<vector<int>> answer(n, vector<int> (n, 0));	
    
	for (int i = 0; i < n; i ++) {
	    for(int j = 0; j < n; j ++) {
	        if(get_root(i) == get_root(j) || p[i][j] != 1) continue ;
	        
	        answer[i][j] = answer[j][i] = 1;
            unite(i, j);
	    }
	}
	
	for(int i = 0; i < n; i ++) {
        if(get_root(i) != i) continue ;
        
        vector<int> row;
        
        for(int j = 0; j < n; j ++) {
            if(p[i][j] != 2) continue ;
            if(mark[j]) return 0;
            row.push_back(j);
        }
        
        if(row.empty()) continue ; 
        
        int root = i;
        int k = i;
        int cnt = 1;
        
        for(int j = 0; j < row.size(); j ++) {
            if(unite(k, row[j])) {
                answer[row[j]][k] = 1;
                answer[k][row[j]] = 1;
                k = row[j];
                cnt ++ ;
            }
        }
        
        answer[root][k] = 1;
        answer[k][root] = 1;
        
        for(int j = 0; j < n; j ++) {
            if(get_root(i) == get_root(j)) {
                mark[j] = 1;
            }
        }
        
        for(int x : row) {
            for(int y : row) {
                if(x == y) continue ;
                if(p[x][y] != 2) return 0;
            }
        }
          
        if(cnt <= 2) return 0;
	}
	
	for(int i = 0; i < n; i ++) {
        if(get_root(i) != i) continue ;
        
        vector<int> row;
        
        for(int j = 0; j < n; j ++) {
            if(p[i][j] != 3) continue ;
            if(mark[j]) return 0;
            row.push_back(j);
        }
        
        if(row.empty()) continue ; 
        
        int root = i;
        int k = i, prev_k = 0;
        int cnt = 1;
        
        for(int j = 0; j < row.size(); j ++) {
            if(unite(k, row[j])) {
                answer[j][k] = 1;
                answer[k][j] = 1;
                
                prev_k = k;
                k = j;
                cnt ++ ;
            }
        }
        
        answer[root][k] = 1;
        answer[k][root] = 1;
        
        answer[root][prev_k] = 1;
        answer[prev_k][root] = 1;
        
        
        for(int j = 0; j < n; j ++) {
            if(get_root(i) == get_root(j)) {
                mark[j] = 1;
            }
        }
        
        for(int x : row) {
            for(int y : row) {
                if(x == y) continue ;
                if(p[x][y] != 2) return 0;
            }
        }
        
        if(cnt <= 3) return 0;
	}
	
  	build(answer);
	return 1;
}

Compilation message

supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:56:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(int j = 0; j < row.size(); j ++) {
      |                        ~~^~~~~~~~~~~~
supertrees.cpp:101:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         for(int j = 0; j < row.size(); j ++) {
      |                        ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1112 KB Output is correct
7 Correct 158 ms 22040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1112 KB Output is correct
7 Correct 158 ms 22040 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 161 ms 22048 KB Output is correct
14 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 7 ms 1324 KB Output is correct
9 Correct 162 ms 22036 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1116 KB Output is correct
13 Correct 158 ms 22020 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 67 ms 12048 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 39 ms 6172 KB Output is correct
22 Correct 155 ms 24144 KB Output is correct
23 Correct 155 ms 23936 KB Output is correct
24 Correct 168 ms 23936 KB Output is correct
25 Correct 62 ms 14160 KB Output is correct
26 Incorrect 159 ms 24148 KB Answer gives possible 1 while actual possible 0
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Correct 40 ms 5724 KB Output is correct
5 Correct 162 ms 22036 KB Output is correct
6 Correct 169 ms 22036 KB Output is correct
7 Correct 161 ms 22100 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 39 ms 5896 KB Output is correct
10 Correct 157 ms 22020 KB Output is correct
11 Correct 156 ms 22024 KB Output is correct
12 Correct 161 ms 22332 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 16 ms 3420 KB Answer gives possible 0 while actual possible 1
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1112 KB Output is correct
7 Correct 158 ms 22040 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 161 ms 22048 KB Output is correct
14 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 7 ms 1112 KB Output is correct
7 Correct 158 ms 22040 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 7 ms 1116 KB Output is correct
13 Correct 161 ms 22048 KB Output is correct
14 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -