답안 #447373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
447373 2021-07-26T08:00:00 Z Habib_Assoev 슈퍼트리 잇기 (IOI20_supertrees) C++14
21 / 100
278 ms 39256 KB
#include "supertrees.h"
#include<bits/stdc++.h>
#define in freopen ("measurement.in", "r", stdin);
#define out freopen("measurement.out", "w", stdout);
#define ll long long
//#define int long long
#define pf push_front
#define fi first
#define se second
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std ;
long long const N = 1e2 + 7;
long long N1 = 1e9 + 7;
const int MOD = 1e9 + 7;

vector < int > used( 1007 );
vector < int > used1( 1007 );
vector < int > used2( 1007 );
vector < vector < int > > k( 1007 );
vector < int > cz;
void dfs( int u ){
    used[u] = 1;
    //cout << "DFS" << ' ' << u << endl;
    cz.push_back( u );
    for( int i = 0 ; i < k[u].size() ; i ++ ){
        ll tr = k[u][i];
        if( used[tr] == 0 ){
            dfs( tr );
        }
    }
}

int construct(std::vector<std::vector<int>> p) {
	int n = p.size();
	std::vector<std::vector<int>> answer;

    for( int i = 0 ; i < n ; i ++ ){
        for( int j = 0 ; j < n ; j ++ ){
            if( p[i][j] == 1 ){
                used2[i] = 1, used2[j] = 1;
                k[j].push_back( i );
                k[i].push_back( j );
            }
        }
    }
    ll a[n][n];
    for( int i = 0 ; i < n ; i ++ ){
        for( int j = 0 ; j < n ; j ++ ){
            a[i][j] = 0;
        }
    }
    ll check = 0;
    for( int i = 0 ; i < n ; i ++ ){
        if( used2[i] == 1 && used[i] == 0 ){
            if( cz.size() > 0 ){
                for( int j = 1 ; j < cz.size() ; j ++ ){
                    a[cz[j]][cz[j-1]] = 1;
                    a[cz[j-1]][cz[j]] = 1;
                }
                for( int j = 0 ; j < cz.size(); j ++ ){
                    for( int h = 0 ; h < cz.size(); h ++ ){
                        if( j != h ){
                           // cout << cz[j] << ' ' << cz[h] << endl;
                            if( p[cz[j]][cz[h]] != 1 ){
                                check = 1;
                                break;
                            }
                        }
                    }
                }
                cz.clear();
            }
            dfs( i );
        }
    }
    if( cz.size() > 0 ){
        for( int j = 1 ; j < cz.size() ; j ++ ){
            a[cz[j]][cz[j-1]] = 1;
            a[cz[j-1]][cz[j]] = 1;
        }
        for( int j = 0 ; j < cz.size(); j ++ ){
            for( int h = 0 ; h < cz.size(); h ++ ){
                if( j != h ){
                    //cout << cz[j] << ' ' << cz[h] << endl;
                    //cout << p[cz[j]][cz[h]] << endl;
                    if( p[cz[j]][cz[h]] != 1 ){
                        check = 1;
                        break;
                    }
                }
            }
        }
        cz.clear();
    }
	for (int i = 0; i < n; i++) {
		std::vector<int> row;
		row.resize(n);
        for( int j = 0 ; j < n ; j ++ ){
            row[j] = a[i][j];
        }
		answer.push_back(row);
	}
	if( check == 0 ){
        build(answer);
        return 1;
	}else{
        return 0;
	}
}

/*

4
0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0

*/

Compilation message

supertrees.cpp: In function 'void dfs(int)':
supertrees.cpp:25:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for( int i = 0 ; i < k[u].size() ; i ++ ){
      |                      ~~^~~~~~~~~~~~~
supertrees.cpp: In function 'int construct(std::vector<std::vector<int> >)':
supertrees.cpp:56:36: 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 = 1 ; j < cz.size() ; j ++ ){
      |                                  ~~^~~~~~~~~~~
supertrees.cpp:60:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                 for( int j = 0 ; j < cz.size(); j ++ ){
      |                                  ~~^~~~~~~~~~~
supertrees.cpp:61:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |                     for( int h = 0 ; h < cz.size(); h ++ ){
      |                                      ~~^~~~~~~~~~~
supertrees.cpp:77:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for( int j = 1 ; j < cz.size() ; j ++ ){
      |                          ~~^~~~~~~~~~~
supertrees.cpp:81:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for( int j = 0 ; j < cz.size(); j ++ ){
      |                          ~~^~~~~~~~~~~
supertrees.cpp:82:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |             for( int h = 0 ; h < cz.size(); h ++ ){
      |                              ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 12 ms 2028 KB Output is correct
7 Correct 260 ms 39256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 12 ms 2028 KB Output is correct
7 Correct 260 ms 39256 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1544 KB Output is correct
13 Correct 229 ms 30652 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 136 ms 26044 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 59 ms 8336 KB Output is correct
21 Correct 234 ms 31684 KB Output is correct
22 Correct 237 ms 30808 KB Output is correct
23 Correct 264 ms 34952 KB Output is correct
24 Correct 278 ms 30808 KB Output is correct
25 Correct 113 ms 22120 KB Output is correct
26 Correct 101 ms 21072 KB Output is correct
27 Correct 261 ms 37060 KB Output is correct
28 Correct 232 ms 30888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 332 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 204 KB Too few ways to get from 0 to 1, should be 2 found 0
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 12 ms 2028 KB Output is correct
7 Correct 260 ms 39256 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1544 KB Output is correct
13 Correct 229 ms 30652 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 136 ms 26044 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 59 ms 8336 KB Output is correct
21 Correct 234 ms 31684 KB Output is correct
22 Correct 237 ms 30808 KB Output is correct
23 Correct 264 ms 34952 KB Output is correct
24 Correct 278 ms 30808 KB Output is correct
25 Correct 113 ms 22120 KB Output is correct
26 Correct 101 ms 21072 KB Output is correct
27 Correct 261 ms 37060 KB Output is correct
28 Correct 232 ms 30888 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Incorrect 1 ms 332 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 12 ms 2028 KB Output is correct
7 Correct 260 ms 39256 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 10 ms 1544 KB Output is correct
13 Correct 229 ms 30652 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 6 ms 1356 KB Output is correct
17 Correct 136 ms 26044 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 328 KB Output is correct
20 Correct 59 ms 8336 KB Output is correct
21 Correct 234 ms 31684 KB Output is correct
22 Correct 237 ms 30808 KB Output is correct
23 Correct 264 ms 34952 KB Output is correct
24 Correct 278 ms 30808 KB Output is correct
25 Correct 113 ms 22120 KB Output is correct
26 Correct 101 ms 21072 KB Output is correct
27 Correct 261 ms 37060 KB Output is correct
28 Correct 232 ms 30888 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Incorrect 1 ms 332 KB Answer gives possible 1 while actual possible 0
33 Halted 0 ms 0 KB -