Submission #447417

# Submission time Handle Problem Language Result Execution time Memory
447417 2021-07-26T09:31:11 Z Habib_Assoev Connecting Supertrees (IOI20_supertrees) C++14
0 / 100
1 ms 332 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;
                }
                ll thy = 0;
                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]] == 0 ){
                                check = 1;
                                break;
                            }
                            if( p[cz[j]][cz[h]] == 2 ){
                                thy = 1;
                            }
                        }
                    }
                }
                if( thy == 1 ){
                    ll fh = cz.size() - 1;
                    a[cz[0]][cz[fh]] = 1;
                    a[cz[fh]][cz[0]] = 1;
                    for( int j = 0 ; j < cz.size(); j ++ ){
                        for( int h = 0 ; h < cz.size(); h ++ ){
                            if( j != h ){
                                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;
        }
        ll thy = 0;
        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]] == 0 ){
                        check = 1;
                        break;
                    }
                    if( p[cz[j]][cz[h]] == 2 ){
                        thy = 1;
                    }
                }
            }
        }
        if( thy == 1 ){
            ll fh = cz.size() - 1;
            a[cz[0]][cz[fh]] = 1;
            a[cz[fh]][cz[0]] = 1;
            for( int j = 0 ; j < cz.size(); j ++ ){
                for( int h = 0 ; h < cz.size(); h ++ ){
                    if( j != h ){
                        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
2 1 0 0
1 0 1 0
0 1 0 1
1 0 0 2

*/

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:61:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |                 for( int j = 0 ; j < cz.size(); j ++ ){
      |                                  ~~^~~~~~~~~~~
supertrees.cpp:62:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |                     for( int h = 0 ; h < cz.size(); h ++ ){
      |                                      ~~^~~~~~~~~~~
supertrees.cpp:80:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |                     for( int j = 0 ; j < cz.size(); j ++ ){
      |                                      ~~^~~~~~~~~~~
supertrees.cpp:81:44: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |                         for( int h = 0 ; h < cz.size(); h ++ ){
      |                                          ~~^~~~~~~~~~~
supertrees.cpp:97:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |         for( int j = 1 ; j < cz.size() ; j ++ ){
      |                          ~~^~~~~~~~~~~
supertrees.cpp:102:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |         for( int j = 0 ; j < cz.size(); j ++ ){
      |                          ~~^~~~~~~~~~~
supertrees.cpp:103:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |             for( int h = 0 ; h < cz.size(); h ++ ){
      |                              ~~^~~~~~~~~~~
supertrees.cpp:121:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |             for( int j = 0 ; j < cz.size(); j ++ ){
      |                              ~~^~~~~~~~~~~
supertrees.cpp:122:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |                 for( int h = 0 ; h < cz.size(); h ++ ){
      |                                  ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB secret mismatch
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB secret mismatch
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Incorrect 1 ms 204 KB Answer gives possible 1 while actual possible 0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 0 ms 204 KB Too few ways to get from 0 to 1, should be 2 found 0
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB secret mismatch
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB secret mismatch
3 Halted 0 ms 0 KB -