Submission #934320

# Submission time Handle Problem Language Result Execution time Memory
934320 2024-02-27T07:17:25 Z GrindMachine Simurgh (IOI17_simurgh) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*



*/

const int MOD = 1e9 + 7;
const int N = 500 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

#include "simurgh.h"

vector<pii> adj[N];
vector<bool> vis(N);
vector<int> tin(N), tout(N), low(N);
vector<array<int,3>> back_edges;
vector<pii> par(N);
int timer;

void dfs1(int u, int p){
	vis[u] = 1;
	tin[u] = low[u] = timer++;
	shuffle(all(adj[u]),rng);

	for(auto [v,id] : adj[u]){
		if(v == p) conts;
		if(vis[v]){
			if(tin[u] > tin[v]){
				back_edges.pb({u,v,id});
			}
			amin(low[u],tin[v]);
		}
		else{
			par[v] = {u,id};
			dfs1(v,u);
			amin(low[u],low[v]);
		}
	}

	tout[u] = timer++;
}

std::vector<int> find_roads(int n, std::vector<int> U, std::vector<int> V) {
	int m = sz(U);
	vector<int> status(m);

	while(count(all(status),1) < n-1){
		rep(i,n){
			adj[i].clear();
			vis[i] = 0;
		}
		back_edges.clear();
		timer = 0;

		rep(i,m){
			if(status[i] != -1){
				int u = U[i], v = V[i];
				adj[u].pb({v,i}), adj[v].pb({u,i});
			}
		}

		dfs1(0,-1);

		if(back_edges.empty()){
			rep(i,m){
				if(status[i] == 0){
					status[i] = 1;
				}
			}

			break;
		}

		auto cmp = [&](array<int,3> &a1, array<int,3> &a2){
			return status[a1[2]] > status[a2[2]];
		};

		sort(all(back_edges),cmp);

		trav(back_edge,back_edges){
			vector<int> spanning;	
			rep1(i,n-1){
				spanning.pb(par[i].ss);
			}
			int original = count_common_roads(spanning);
			auto [u,v,id] = back_edge;

			if(status[id] == 1){
				// back edge is definitely good
				while(u != v){
					auto [p,pid] = par[u];
					if(status[pid] != 0){
						u = p;
						conts;
					}

					spanning.erase(find(all(spanning),pid));
					spanning.pb(id);
					int curr = count_common_roads(spanning);
					spanning.pop_back();
					spanning.pb(pid);

					if(curr < original){
						assert(0);
					}
					else if(curr == original){
						status[pid] = 1;
					}
					else{
						status[pid] = -1;
					}

					u = p;
				}
			}
			else{
				// back edge may/may not be good
				int bad_cnt = 0;
				vector<int> same_edges;
				same_edges.pb(id);

				while(u != v){
					auto [p,pid] = par[u];
					if(status[pid] != 0){
						bad_cnt += (status[pid] == -1);
						u = p;
						conts;
					}

					spanning.erase(find(all(spanning),pid));
					spanning.pb(id);
					int curr = count_common_roads(spanning);
					spanning.pop_back();
					spanning.pb(pid);

					if(curr < original){
						status[pid] = 1;
					}
					else if(curr == original){
						same_edges.pb(pid);
					}
					else{
						status[pid] = -1;
						bad_cnt++;
					}

					u = p;
				}

				if(bad_cnt){
					trav(edge_id,same_edges){
						status[edge_id] = 1;
					}
				}
				else{
					trav(edge_id,same_edges){
						status[edge_id] = -1;
					}
				}

				break;
			}
		}

		// if(status[id] == 1){
		// 	// back edge is definitely good
		// 	while(u != v){
		// 		auto [p,pid] = par[u];
		// 		if(status[pid] == 1){
		// 			u = p;
		// 			conts;
		// 		}

		// 		spanning.erase(find(all(spanning),pid));
		// 		spanning.pb(id);
		// 		int curr = count_common_roads(spanning);
		// 		spanning.pop_back();
		// 		spanning.pb(pid);

		// 		if(curr < original){
		// 			assert(0);
		// 		}
		// 		else if(curr == original){
		// 			status[pid] = 1;
		// 		}
		// 		else{
		// 			status[pid] = -1;
		// 		}

		// 		u = p;
		// 	}
		// }
		// else{
		// 	// back edge may/may not be good
		// 	int bad_cnt = 0;
		// 	vector<int> same_edges;
		// 	same_edges.pb(id);

		// 	while(u != v){
		// 		auto [p,pid] = par[u];
		// 		if(status[pid] == 1){
		// 			u = p;
		// 			conts;
		// 		}

		// 		spanning.erase(find(all(spanning),pid));
		// 		spanning.pb(id);
		// 		int curr = count_common_roads(spanning);
		// 		spanning.pop_back();
		// 		spanning.pb(pid);

		// 		if(curr < original){
		// 			status[pid] = 1;
		// 		}
		// 		else if(curr == original){
		// 			same_edges.pb(pid);
		// 		}
		// 		else{
		// 			status[pid] = -1;
		// 			bad_cnt++;
		// 		}

		// 		u = p;
		// 	}

		// 	if(bad_cnt){
		// 		trav(edge_id,same_edges){
		// 			status[edge_id] = 1;
		// 		}
		// 	}
		// 	else{
		// 		trav(edge_id,same_edges){
		// 			status[edge_id] = -1;
		// 		}
		// 	}
		// }
	}

	vector<int> ans;
	rep(i,m){
		if(status[i] == 1){
			ans.pb(i);
		}
	}

	debug(ans);

	return ans;
}

Compilation message

simurgh.cpp: In function 'void dfs1(int, int)':
simurgh.cpp:72:22: error: 'rng' was not declared in this scope
   72 |  shuffle(all(adj[u]),rng);
      |                      ^~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:46:18: warning: statement has no effect [-Wunused-value]
   46 | #define debug(x) 42
      |                  ^~
simurgh.cpp:295:2: note: in expansion of macro 'debug'
  295 |  debug(ans);
      |  ^~~~~