답안 #934324

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934324 2024-02-27T07:19:59 Z GrindMachine Simurgh (IOI17_simurgh) C++17
30 / 100
3000 ms 3916 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);
array<int,3> back_edge;
vector<pii> par(N);
int timer;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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_edge = {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_edge = {-1,-1,-1};
		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);
 
		auto [u,v,id] = back_edge;
			
		vector<int> spanning;	
		rep1(i,n-1){
			spanning.pb(par[i].ss);
		}
 
		if(back_edge[0] == -1){
			rep(i,m){
				if(status[i] == 0){
					status[i] = 1;
				}
			}
 
			break;
		}
 
		int original = count_common_roads(spanning);
 
		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 '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:214:2: note: in expansion of macro 'debug'
  214 |  debug(ans);
      |  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 14 ms 344 KB correct
15 Correct 8 ms 348 KB correct
16 Correct 16 ms 344 KB correct
17 Correct 10 ms 348 KB correct
18 Correct 2 ms 348 KB correct
19 Correct 10 ms 348 KB correct
20 Correct 11 ms 348 KB correct
21 Correct 8 ms 348 KB correct
22 Correct 6 ms 428 KB correct
23 Correct 5 ms 348 KB correct
24 Correct 5 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 5 ms 344 KB correct
27 Correct 5 ms 348 KB correct
28 Correct 2 ms 344 KB correct
29 Correct 1 ms 348 KB correct
30 Correct 5 ms 344 KB correct
31 Correct 4 ms 348 KB correct
32 Correct 4 ms 500 KB correct
33 Correct 4 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 14 ms 344 KB correct
15 Correct 8 ms 348 KB correct
16 Correct 16 ms 344 KB correct
17 Correct 10 ms 348 KB correct
18 Correct 2 ms 348 KB correct
19 Correct 10 ms 348 KB correct
20 Correct 11 ms 348 KB correct
21 Correct 8 ms 348 KB correct
22 Correct 6 ms 428 KB correct
23 Correct 5 ms 348 KB correct
24 Correct 5 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 5 ms 344 KB correct
27 Correct 5 ms 348 KB correct
28 Correct 2 ms 344 KB correct
29 Correct 1 ms 348 KB correct
30 Correct 5 ms 344 KB correct
31 Correct 4 ms 348 KB correct
32 Correct 4 ms 500 KB correct
33 Correct 4 ms 348 KB correct
34 Execution timed out 3036 ms 1372 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Execution timed out 3094 ms 3916 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 0 ms 348 KB correct
8 Correct 0 ms 348 KB correct
9 Correct 0 ms 348 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 14 ms 344 KB correct
15 Correct 8 ms 348 KB correct
16 Correct 16 ms 344 KB correct
17 Correct 10 ms 348 KB correct
18 Correct 2 ms 348 KB correct
19 Correct 10 ms 348 KB correct
20 Correct 11 ms 348 KB correct
21 Correct 8 ms 348 KB correct
22 Correct 6 ms 428 KB correct
23 Correct 5 ms 348 KB correct
24 Correct 5 ms 344 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 5 ms 344 KB correct
27 Correct 5 ms 348 KB correct
28 Correct 2 ms 344 KB correct
29 Correct 1 ms 348 KB correct
30 Correct 5 ms 344 KB correct
31 Correct 4 ms 348 KB correct
32 Correct 4 ms 500 KB correct
33 Correct 4 ms 348 KB correct
34 Execution timed out 3036 ms 1372 KB Time limit exceeded
35 Halted 0 ms 0 KB -