Submission #879397

#TimeUsernameProblemLanguageResultExecution timeMemory
879397vladburacStranded Far From Home (BOI22_island)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int NMAX = 2e5; pair<int, int> v[NMAX+1]; vector <int> edges[NMAX+1]; int parent[NMAX+1]; bool viz[NMAX+1]; int marked[NMAX+1]; ll sum[NMAX+1]; pair<int, bool> findd( int x ) { // parintele si daca am marcat pe lant pana la radacina if( parent[x] == x ) return { x, marked[x] }; x = findd( parent[x] ); return { x.first, x.second | marked[x.first] }; } void unite( int a, int b, int nxtWeight ) { int x = findd( a ); int y = findd( b ); if( x != y ) { parent[x] = y; sum[y] += sum[x]; if( sum[y] < nxtWeight ) marked[y] = true; } } void solve() { int n, m, i, a, b; cin >> n >> m; for( i = 0; i < n; i++ ) { cin >> v[i].first; v[i].second = i; parent[i] = i; viz[i] = false; sum[i] = v[i].first; } v[n].first = 0; for( i = 0; i < m; i++ ) { cin >> a >> b; a--, b--; edges[a].push_back( b ); edges[b].push_back( a ); } sort( v, v + n ); for( i = 0; i < n; i++ ) { viz[v[i].second] = true; bool linked = false; for( auto vec: edges[v[i].second] ) { if( viz[vec] ) { unite( v[i].second, vec, v[i+1].first ); linked = true; } } if( !linked && v[i].first < v[i+1].first ) marked[v[i].second] = true; } for( i = 0; i < n; i++ ) a = findd( i ); for( i = 0; i < n; i++ ) cout << 1 - marked[i]; cout << "\n"; } int main() { //ios_base::sync_with_stdio( false ); //cin.tie( NULL ); //cout.tie( NULL ); int t = 1; //cin >> t; while( t-- ) solve(); return 0; }

Compilation message (stderr)

island.cpp: In function 'std::pair<int, bool> findd(int)':
island.cpp:16:12: error: cannot convert 'std::pair<int, bool>' to 'int' in assignment
   16 |   x = findd( parent[x] );
      |       ~~~~~^~~~~~~~~~~~~
      |            |
      |            std::pair<int, bool>
island.cpp:17:14: error: request for member 'first' in 'x', which is of non-class type 'int'
   17 |   return { x.first, x.second | marked[x.first] };
      |              ^~~~~
island.cpp:17:23: error: request for member 'second' in 'x', which is of non-class type 'int'
   17 |   return { x.first, x.second | marked[x.first] };
      |                       ^~~~~~
island.cpp:17:41: error: request for member 'first' in 'x', which is of non-class type 'int'
   17 |   return { x.first, x.second | marked[x.first] };
      |                                         ^~~~~
island.cpp:17:48: error: could not convert '{<expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::pair<int, bool>'
   17 |   return { x.first, x.second | marked[x.first] };
      |                                                ^
      |                                                |
      |                                                <brace-enclosed initializer list>
island.cpp: In function 'void unite(int, int, int)':
island.cpp:21:16: error: cannot convert 'std::pair<int, bool>' to 'int' in initialization
   21 |   int x = findd( a );
      |           ~~~~~^~~~~
      |                |
      |                std::pair<int, bool>
island.cpp:22:16: error: cannot convert 'std::pair<int, bool>' to 'int' in initialization
   22 |   int y = findd( b );
      |           ~~~~~^~~~~
      |                |
      |                std::pair<int, bool>
island.cpp: In function 'void solve()':
island.cpp:61:14: error: cannot convert 'std::pair<int, bool>' to 'int' in assignment
   61 |     a = findd( i );
      |         ~~~~~^~~~~
      |              |
      |              std::pair<int, bool>