Submission #133891

# Submission time Handle Problem Language Result Execution time Memory
133891 2019-07-21T16:34:40 Z nvmdava Simurgh (IOI17_simurgh) C++17
Compilation error
0 ms 0 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define N 505
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<int> inq, tree ACpls, adj[N], cyc, fin, onn, off, vall, imsad;
vector<pair<int, int> > edge;
int n, m, par[N], dep[N], p[N], t;
bool ans[150000], c[150000], in[N];

int get(int v, int i){
	return edge[i].ff + edge[i].ss - v;
}

void reset(){
	for(int i = 0; i < n; i++)
		p[i] = i;
}

int find(int v){
	return v == p[v] ? v : p[v] = find(p[v]);
}

bool merge(int v, int u){
	v = find(v);
	u = find(u);
	if(v == u) return 0;
	p[v] = u;
	return 1;
}

int ask(){
	reset();
	for(int& x : inq)
		merge(edge[x].ff, edge[x].ss);
	t = 0;
	for(int& x : tree){
		if(merge(edge[x].ff, edge[x].ss)){
			inq.pb(x);
			t += ans[x];
		}
	}
	return count_common_roads(inq);
}

void dfs(int v){
	for(int& x : adj[v]){
		int u = get(v, x);
		if(dep[u]) continue;
		par[u] = x;
		dep[u] = dep[v] + 1;
		tree.pb(x);
		dfs(u);
	}
}

int fillexc(int x){
	inq = cyc;
	for(int& a : inq){
		if(a == x){
			swap(a, inq.back());
			inq.pop_back();
			break;
		}
	}
	return ask();
}

void solvecycle(){
	if(fin.empty()) return;
	if(onn.empty() && off.empty()){
		int lo = -1;
		vall.clear();
		for(int& x : cyc)
			vall.pb(fillexc(x));
		for(int& x : vall)
			lo = max(lo, x);
		for(int i = cyc.size() - 1; i >= 0; i--){
			ch[cyc[i]] = 1;
			ans[cyc[i]] = (lo - vall[i]);
		}
	} else {
		int lo;
		if(off.empty())
			lo = fillexc(onn[0]);
		else 
			lo = fillexc(off[0]) - 1;
		for(int& x : fin){
			ch[x] = 1;
			ans[x] = (fillexc(x) == lo);
		}
	}
}

void solvetree(){
	for(int i = 0; i < m; i++){
		if(dep[edge[i].ff] < dep[edge[i].ss]) swap(edge[i].ff, edge[i].ss);
		if(dep[edge[i].ff] - dep[edge[i].ss] == 1) continue;
		cyc.clear(); fin.clear(); off.clear(); onn.clear();
		cyc.pb(i);
		int s = edge[i].ff;
		while(s != edge[i].ss){
			cyc.pb(par[s]);
			if(ch[par[s]] == 0) fin.pb(par[s]);
			else if(ans[par[s]] == 1) onn.pb(par[s]);
			else off.pb(par[s]);
			s = get(s, par[s]);
		}
		solvecycle();
	}
	for(int& x : tree){
		if(ch[x] == 0){
			ch[x] = ans[x] = 1;
		}
	}
}

void dfs2(int v){
	in[v] = 1;
	for(int i = adj[v].size() - 1; i >= 0; i--){
		if(ch[adj[v][i]]){
			swap(adj[v][i], adj[v].back());
			adj[v].pop_back();
			continue;
		}
		int u = get(v, adj[v][i]);
		if(in[u]) continue;
		imsad.pb(adj[v][i]);
		dfs2(u);
	}
}

void solvethisshit(){
	if(imsad.empty()) return;
	inq = imsad;
	if(ask() == t){
		for(int& x : imsad){
			ch[x] = 1;
			ans[x] = 0;
		}
		return;
	}
	int l = 0, r = imsad.size() - 1;
	while(l != r){
		int m = (l + r) >> 1;
		inq.clear();
		for(int i = 0; i <= m; i++)
			inq.pb(imsad[i]);
		if(ask() == t) l = m + 1;
		else r = m;
	}
	for(int i = 0; i < r; i++){
		ch[imsad[i]] = 1;
		ans[imsad[i]] = 0;
	}
	ch[imsad[r]] = ans[imsad[r]] = 1;
}


vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	::n = n;
	m = u.size();
	for(int i = 0; i < m; i++){
		adj[v[i]].pb(i);
		adj[u[i]].pb(i);
		edge.pb({v[i], u[i]});
	}
	dep[0] = 1;
	dfs(0);
	if(m == n - 1){
		return tree; 
	}
	solvetree();
	do{
		memset(in, 0, sizeof in);
		imsad.clear();
		for(int i = 0; i < n; i++){
			if(in[i]) continue;
			dfs2(i);
		}
		solvethisshit();
	} while(!imsad.empty());
	return ACpls;
}

Compilation message

simurgh.cpp:9:23: error: expected initializer before 'ACpls'
 vector<int> inq, tree ACpls, adj[N], cyc, fin, onn, off, vall, imsad;
                       ^~~~~
simurgh.cpp: In function 'int ask()':
simurgh.cpp:40:15: error: 'tree' was not declared in this scope
  for(int& x : tree){
               ^~~~
simurgh.cpp:40:15: note: suggested alternative: 'free'
  for(int& x : tree){
               ^~~~
               free
simurgh.cpp: In function 'void dfs(int)':
simurgh.cpp:50:15: error: 'adj' was not declared in this scope
  for(int& x : adj[v]){
               ^~~
simurgh.cpp:55:3: error: 'tree' was not declared in this scope
   tree.pb(x);
   ^~~~
simurgh.cpp:55:3: note: suggested alternative: 'free'
   tree.pb(x);
   ^~~~
   free
simurgh.cpp: In function 'int fillexc(int)':
simurgh.cpp:61:8: error: 'cyc' was not declared in this scope
  inq = cyc;
        ^~~
simurgh.cpp: In function 'void solvecycle()':
simurgh.cpp:73:5: error: 'fin' was not declared in this scope
  if(fin.empty()) return;
     ^~~
simurgh.cpp:73:5: note: suggested alternative: 'find'
  if(fin.empty()) return;
     ^~~
     find
simurgh.cpp:74:5: error: 'onn' was not declared in this scope
  if(onn.empty() && off.empty()){
     ^~~
simurgh.cpp:74:20: error: 'off' was not declared in this scope
  if(onn.empty() && off.empty()){
                    ^~~
simurgh.cpp:74:20: note: suggested alternative: 'ff'
  if(onn.empty() && off.empty()){
                    ^~~
                    ff
simurgh.cpp:76:3: error: 'vall' was not declared in this scope
   vall.clear();
   ^~~~
simurgh.cpp:76:3: note: suggested alternative: 'kill'
   vall.clear();
   ^~~~
   kill
simurgh.cpp:77:16: error: 'cyc' was not declared in this scope
   for(int& x : cyc)
                ^~~
simurgh.cpp:79:16: error: unable to deduce 'auto&&' from 'vall'
   for(int& x : vall)
                ^~~~
simurgh.cpp:81:15: error: 'cyc' was not declared in this scope
   for(int i = cyc.size() - 1; i >= 0; i--){
               ^~~
simurgh.cpp:82:4: error: 'ch' was not declared in this scope
    ch[cyc[i]] = 1;
    ^~
simurgh.cpp:82:4: note: suggested alternative: 'c'
    ch[cyc[i]] = 1;
    ^~
    c
simurgh.cpp:91:16: error: 'fin' was not declared in this scope
   for(int& x : fin){
                ^~~
simurgh.cpp:91:16: note: suggested alternative: 'find'
   for(int& x : fin){
                ^~~
                find
simurgh.cpp:92:4: error: 'ch' was not declared in this scope
    ch[x] = 1;
    ^~
simurgh.cpp:92:4: note: suggested alternative: 'c'
    ch[x] = 1;
    ^~
    c
simurgh.cpp: In function 'void solvetree()':
simurgh.cpp:102:3: error: 'cyc' was not declared in this scope
   cyc.clear(); fin.clear(); off.clear(); onn.clear();
   ^~~
simurgh.cpp:102:16: error: 'fin' was not declared in this scope
   cyc.clear(); fin.clear(); off.clear(); onn.clear();
                ^~~
simurgh.cpp:102:16: note: suggested alternative: 'find'
   cyc.clear(); fin.clear(); off.clear(); onn.clear();
                ^~~
                find
simurgh.cpp:102:29: error: 'off' was not declared in this scope
   cyc.clear(); fin.clear(); off.clear(); onn.clear();
                             ^~~
simurgh.cpp:102:29: note: suggested alternative: 'ff'
   cyc.clear(); fin.clear(); off.clear(); onn.clear();
                             ^~~
                             ff
simurgh.cpp:102:42: error: 'onn' was not declared in this scope
   cyc.clear(); fin.clear(); off.clear(); onn.clear();
                                          ^~~
simurgh.cpp:107:7: error: 'ch' was not declared in this scope
    if(ch[par[s]] == 0) fin.pb(par[s]);
       ^~
simurgh.cpp:107:7: note: suggested alternative: 'c'
    if(ch[par[s]] == 0) fin.pb(par[s]);
       ^~
       c
simurgh.cpp:114:15: error: 'tree' was not declared in this scope
  for(int& x : tree){
               ^~~~
simurgh.cpp:114:15: note: suggested alternative: 'free'
  for(int& x : tree){
               ^~~~
               free
simurgh.cpp:115:6: error: 'ch' was not declared in this scope
   if(ch[x] == 0){
      ^~
simurgh.cpp:115:6: note: suggested alternative: 'c'
   if(ch[x] == 0){
      ^~
      c
simurgh.cpp: In function 'void dfs2(int)':
simurgh.cpp:123:14: error: 'adj' was not declared in this scope
  for(int i = adj[v].size() - 1; i >= 0; i--){
              ^~~
simurgh.cpp:124:6: error: 'ch' was not declared in this scope
   if(ch[adj[v][i]]){
      ^~
simurgh.cpp:124:6: note: suggested alternative: 'c'
   if(ch[adj[v][i]]){
      ^~
      c
simurgh.cpp:131:3: error: 'imsad' was not declared in this scope
   imsad.pb(adj[v][i]);
   ^~~~~
simurgh.cpp: In function 'void solvethisshit()':
simurgh.cpp:137:5: error: 'imsad' was not declared in this scope
  if(imsad.empty()) return;
     ^~~~~
simurgh.cpp:138:8: error: 'imsad' was not declared in this scope
  inq = imsad;
        ^~~~~
simurgh.cpp:140:16: error: unable to deduce 'auto&&' from 'imsad'
   for(int& x : imsad){
                ^~~~~
simurgh.cpp:141:4: error: 'ch' was not declared in this scope
    ch[x] = 1;
    ^~
simurgh.cpp:141:4: note: suggested alternative: 'c'
    ch[x] = 1;
    ^~
    c
simurgh.cpp:156:3: error: 'ch' was not declared in this scope
   ch[imsad[i]] = 1;
   ^~
simurgh.cpp:156:3: note: suggested alternative: 'c'
   ch[imsad[i]] = 1;
   ^~
   c
simurgh.cpp:159:2: error: 'ch' was not declared in this scope
  ch[imsad[r]] = ans[imsad[r]] = 1;
  ^~
simurgh.cpp:159:2: note: suggested alternative: 'c'
  ch[imsad[r]] = ans[imsad[r]] = 1;
  ^~
  c
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:167:3: error: 'adj' was not declared in this scope
   adj[v[i]].pb(i);
   ^~~
simurgh.cpp:174:10: error: 'tree' was not declared in this scope
   return tree; 
          ^~~~
simurgh.cpp:174:10: note: suggested alternative: 'free'
   return tree; 
          ^~~~
          free
simurgh.cpp:179:3: error: 'imsad' was not declared in this scope
   imsad.clear();
   ^~~~~
simurgh.cpp:185:11: error: 'imsad' was not declared in this scope
  } while(!imsad.empty());
           ^~~~~
simurgh.cpp:186:9: error: 'ACpls' was not declared in this scope
  return ACpls;
         ^~~~~