답안 #853581

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853581 2023-09-24T16:58:25 Z ntkphong 슈퍼트리 잇기 (IOI20_supertrees) C++14
46 / 100
196 ms 22304 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;
            }
        }
          
        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;
            }
        }
        
        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:94:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for(int j = 0; j < row.size(); j ++) {
      |                        ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 162 ms 22136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 162 ms 22136 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 7 ms 1112 KB Output is correct
13 Correct 162 ms 22096 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 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 7 ms 1316 KB Output is correct
9 Correct 168 ms 21952 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 7 ms 1112 KB Output is correct
13 Correct 164 ms 22304 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 3 ms 860 KB Output is correct
17 Correct 68 ms 14072 KB Output is correct
18 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 600 KB Output is correct
4 Correct 40 ms 5836 KB Output is correct
5 Correct 162 ms 22096 KB Output is correct
6 Correct 162 ms 22096 KB Output is correct
7 Correct 171 ms 21952 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 40 ms 5720 KB Output is correct
10 Correct 159 ms 22068 KB Output is correct
11 Correct 161 ms 22060 KB Output is correct
12 Correct 184 ms 22036 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 40 ms 5712 KB Output is correct
17 Correct 158 ms 22096 KB Output is correct
18 Correct 196 ms 22092 KB Output is correct
19 Correct 164 ms 22096 KB Output is correct
20 Correct 165 ms 22100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 162 ms 22136 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 7 ms 1112 KB Output is correct
13 Correct 162 ms 22096 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 1 ms 344 KB Output is correct
2 Correct 0 ms 344 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 344 KB Output is correct
6 Correct 7 ms 1116 KB Output is correct
7 Correct 162 ms 22136 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 7 ms 1112 KB Output is correct
13 Correct 162 ms 22096 KB Output is correct
14 Incorrect 0 ms 344 KB Answer gives possible 1 while actual possible 0
15 Halted 0 ms 0 KB -