Submission #46756

# Submission time Handle Problem Language Result Execution time Memory
46756 2018-04-22T21:50:11 Z wzy ICC (CEOI16_icc) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;

int pai[150] , peso[150];

vector<int> linked[152];

int fd(int x){
	return pai[x] == x ? x : pai[x] = fd(pai[x]);
}

void join(int u , int v){
	u = fd(u) , v= fd(v);
	if(peso[u] > peso[v]) swap(u,v);
	pai[u] = v , peso[v] += peso[u] + 1;
	for(int j = 0 ; j < linked[u].size() ; j++) linked[v].push_back(linked[u][j]);
	linked[u].clear();
}

bool get(vector<int> l , vector<int> r){
	if(l.size() == 0 || r.size() == 0) return 0;
	bool w = query(l.size() , r.size() , l , r);
	if(!w){
		vector<int> ll , rr;
		for(int i = 0 ; i < l.size() ; i++){
			if(ll.size() && fd(ll.back()) == fd(l[i])){
				ll.pb(l[i]);
			}
			else if(rr.size() && fd(rr.back()) == fd(l[i])) rr.pb(l[i]);
			else{
				if(ll.size() < rr.size()) ll.pb(l[i]);
				else rr.pb(l[i]);
			}
		}
		bool q = get(ll , rr);
		if(!q){
			vector<int> lr, rl;
			for(int i = 0 ; i < r.size() ; i++){
				if(lr.size() && fd(r[i]) == fd(lr.back())){
					lr.pb(r[i]);
				}	
				else if(rl.size() && fd(r[i]) == fd(rl.back())) rl.pb(r[i]);
				else{
					if(lr.size() < rr.size()) lr.pb(r[i]);
					else rl.pb(r[i]);
				}
			}
			q = get(lr , rl);
		}
		return q;
	}
	else{
		int ll = 0 , rr = l.size() - 1;
		int ansj = -1;
		while(ll<=rr){
			int mid = (ll + rr) / 2;
			vector<int> opt;
			for(int j = 0 ; j <= mid ; j++) opt.pb(l[j]);
			bool q = query(opt.size() , r.size() , opt, r);
			if(q){
				rr = mid - 1;
				ansj = mid;
			}
			else ll = mid + 1;
		}
		ll = 0 , rr = r.size() - 1;
		int ansj2 = -1;
		while(ll <= rr){
			int mid = (ll +rr)/2;
			vector<int> opt;
			for(int j = 0 ; j <= mid; j++) opt.pb(r[j]);
				bool q = query(opt.size() , l.size() , opt, l);
			if(q){
				rr = mid - 1;
				ansj2 = mid;
			}
			else ll = mid + 1;
		}
		setRoad(l[ansj] , r[ansj2]);
		
		return true;
	}
}


void run(int n){
	for(int i = 0 ; i <= n; i++) pai[i] = i , peso[i] = 0 , linked[i].pb(i);
	for(int i = 0 ; i < n - 1 ; i++){
		set<int> dependencies;
		for(int j = 1 ; j <= n; j ++) dependencies.insert(j);
		vector<int> l , r;
		for(int j = 1 ; j <= n; j++){
			if(!dependencies.count(j)) continue;
			if(l.size() < r.size()){
				for(int w = 0 ; w < linked[fd(j)].size() ; w++){
					l.pb(linked[fd(j)][w]);
					dependencies.erase(linked[fd(j)][w]);
				}
			}
			else{
				for(int w = 0 ; w < linked[fd(j)].size(); w++){
					r.pb(linked[fd(j)][w]);
					dependencies.erase(linked[fd(j)][w]);
				}
			}
		}
		get(l , r);
	}
}


Compilation message

icc.cpp: In function 'void join(int, int)':
icc.cpp:17:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int j = 0 ; j < linked[u].size() ; j++) linked[v].push_back(linked[u][j]);
                  ~~^~~~~~~~~~~~~~~~~~
icc.cpp: In function 'bool get(std::vector<int>, std::vector<int>)':
icc.cpp:23:44: error: cannot convert 'std::vector<int>' to 'int*' for argument '3' to 'int query(int, int, int*, int*)'
  bool w = query(l.size() , r.size() , l , r);
                                            ^
icc.cpp:26:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0 ; i < l.size() ; i++){
                   ~~^~~~~~~~~~
icc.cpp:28:8: error: 'class std::vector<int>' has no member named 'pb'
     ll.pb(l[i]);
        ^~
icc.cpp:30:55: error: 'class std::vector<int>' has no member named 'pb'
    else if(rr.size() && fd(rr.back()) == fd(l[i])) rr.pb(l[i]);
                                                       ^~
icc.cpp:32:34: error: 'class std::vector<int>' has no member named 'pb'
     if(ll.size() < rr.size()) ll.pb(l[i]);
                                  ^~
icc.cpp:33:13: error: 'class std::vector<int>' has no member named 'pb'
     else rr.pb(l[i]);
             ^~
icc.cpp:39:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i = 0 ; i < r.size() ; i++){
                    ~~^~~~~~~~~~
icc.cpp:41:9: error: 'class std::vector<int>' has no member named 'pb'
      lr.pb(r[i]);
         ^~
icc.cpp:43:56: error: 'class std::vector<int>' has no member named 'pb'
     else if(rl.size() && fd(r[i]) == fd(rl.back())) rl.pb(r[i]);
                                                        ^~
icc.cpp:45:35: error: 'class std::vector<int>' has no member named 'pb'
      if(lr.size() < rr.size()) lr.pb(r[i]);
                                   ^~
icc.cpp:46:14: error: 'class std::vector<int>' has no member named 'pb'
      else rl.pb(r[i]);
              ^~
icc.cpp:59:40: error: 'class std::vector<int>' has no member named 'pb'
    for(int j = 0 ; j <= mid ; j++) opt.pb(l[j]);
                                        ^~
icc.cpp:60:49: error: cannot convert 'std::vector<int>' to 'int*' for argument '3' to 'int query(int, int, int*, int*)'
    bool q = query(opt.size() , r.size() , opt, r);
                                                 ^
icc.cpp:72:39: error: 'class std::vector<int>' has no member named 'pb'
    for(int j = 0 ; j <= mid; j++) opt.pb(r[j]);
                                       ^~
icc.cpp:73:50: error: cannot convert 'std::vector<int>' to 'int*' for argument '3' to 'int query(int, int, int*, int*)'
     bool q = query(opt.size() , l.size() , opt, l);
                                                  ^
icc.cpp: In function 'void run(int)':
icc.cpp:88:68: error: 'class std::vector<int>' has no member named 'pb'
  for(int i = 0 ; i <= n; i++) pai[i] = i , peso[i] = 0 , linked[i].pb(i);
                                                                    ^~
icc.cpp:96:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int w = 0 ; w < linked[fd(j)].size() ; w++){
                     ~~^~~~~~~~~~~~~~~~~~~~~~
icc.cpp:97:8: error: 'class std::vector<int>' has no member named 'pb'
      l.pb(linked[fd(j)][w]);
        ^~
icc.cpp:102:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int w = 0 ; w < linked[fd(j)].size(); w++){
                     ~~^~~~~~~~~~~~~~~~~~~~~~
icc.cpp:103:8: error: 'class std::vector<int>' has no member named 'pb'
      r.pb(linked[fd(j)][w]);
        ^~