답안 #934285

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934285 2024-02-27T06:13:00 Z GrindMachine Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 456 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<int> back_edges(N);
vector<pii> par(N);
int timer;

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

	for(auto [v,id] : adj[u]){
		if(v == p) conts;
		if(vis[v]){
			if(tin[u] > tin[v]){
				back_edges[u]++;
			}
			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) {
	vector<array<int,3>> edges;
	rep(i,sz(U)){
		int u = U[i], v = V[i];
		edges.pb({u,v,i});
	}

	auto in_sub = [&](int u, int v){
		// is u in the sub of v?
		return tin[u] >= tin[v] and tout[u] <= tout[v];
	};

	while(sz(edges) >= n){
		rep(i,n){
			adj[i].clear();
			vis[i] = 0;
			back_edges[i] = 0;
		}
		timer = 0;

		for(auto [u,v,id] : edges){
			adj[u].pb({v,id}), adj[v].pb({u,id});
		}

		dfs1(0,-1);

		vector<bool> good(sz(U));

		vector<int> spanning;
		rep1(i,n-1){
			spanning.pb(par[i].ss);
			good[par[i].ss] = 1;
		}

		rep(i,n){
			if(!back_edges[i]) conts;
			auto [p,pid] = par[i];
			spanning.erase(find(all(spanning),pid));
			spanning.pb(pid);
			vector<array<int,3>> consider;
			vector<array<int,3>> edges2;

			for(auto [u,v,id] : edges){
				if(good[id]){
					if(id != pid){
						edges2.pb({u,v,id});
					}
					conts;
				}

				// does this edge cross through i?
				// 1 node in sub of u, other outside sub of u (wlog, depth(u) > depth(v))
				if(tin[u] < tin[v]) swap(u,v);
				if(in_sub(u,i) and !in_sub(v,i)){
					consider.pb({u,v,id});
				}
				else{
					edges2.pb({u,v,id});
				}
			}

			int original = count_common_roads(spanning);
			bool spanning_ok = true;

			for(auto [u,v,id] : consider){
				spanning.pop_back();
				spanning.pb(id);
				int curr = count_common_roads(spanning);
				if(curr > original){
					spanning_ok = false;
					edges2.pb({u,v,id});
				}
				spanning.pop_back();
				spanning.pb(pid);
			}

			if(spanning_ok){
				edges2.pb({i,p,pid});
			}

			edges = edges2;
			break;
		}
	}

	vector<int> ans;
	for(auto [u,v,id] : edges){
		ans.pb(id);
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 456 KB correct
2 Incorrect 0 ms 348 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -