답안 #934489

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
934489 2024-02-27T12:43:12 Z GrindMachine Simurgh (IOI17_simurgh) C++17
30 / 100
2949 ms 5580 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;
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_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;
		}
 
		vector<int> spanning;	
		rep1(i,n-1){
			spanning.pb(par[i].ss);
		}
 
		int original = count_common_roads(spanning);
 	
 		for(auto [u,v,id] : back_edges){
			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;
					}

					break;
				}
			}
 		}
	}
 
	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:216:2: note: in expansion of macro 'debug'
  216 |  debug(ans);
      |  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 1 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 600 KB correct
9 Correct 1 ms 344 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 1 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 1 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 600 KB correct
9 Correct 1 ms 344 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 1 ms 348 KB correct
14 Correct 8 ms 348 KB correct
15 Correct 8 ms 344 KB correct
16 Correct 8 ms 344 KB correct
17 Correct 6 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 6 ms 348 KB correct
20 Correct 5 ms 548 KB correct
21 Correct 5 ms 348 KB correct
22 Correct 3 ms 348 KB correct
23 Correct 3 ms 348 KB correct
24 Correct 3 ms 520 KB correct
25 Correct 1 ms 348 KB correct
26 Correct 3 ms 348 KB correct
27 Correct 4 ms 348 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 1 ms 344 KB correct
30 Correct 3 ms 348 KB correct
31 Correct 3 ms 348 KB correct
32 Correct 3 ms 348 KB correct
33 Correct 3 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 1 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 600 KB correct
9 Correct 1 ms 344 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 1 ms 348 KB correct
14 Correct 8 ms 348 KB correct
15 Correct 8 ms 344 KB correct
16 Correct 8 ms 344 KB correct
17 Correct 6 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 6 ms 348 KB correct
20 Correct 5 ms 548 KB correct
21 Correct 5 ms 348 KB correct
22 Correct 3 ms 348 KB correct
23 Correct 3 ms 348 KB correct
24 Correct 3 ms 520 KB correct
25 Correct 1 ms 348 KB correct
26 Correct 3 ms 348 KB correct
27 Correct 4 ms 348 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 1 ms 344 KB correct
30 Correct 3 ms 348 KB correct
31 Correct 3 ms 348 KB correct
32 Correct 3 ms 348 KB correct
33 Correct 3 ms 348 KB correct
34 Correct 1815 ms 2072 KB correct
35 Correct 1731 ms 2140 KB correct
36 Correct 796 ms 2072 KB correct
37 Correct 8 ms 344 KB correct
38 Correct 1794 ms 2336 KB correct
39 Correct 1274 ms 2080 KB correct
40 Correct 861 ms 2076 KB correct
41 Incorrect 1850 ms 2332 KB WA in grader: NO
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 1 ms 348 KB correct
3 Incorrect 2949 ms 5580 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 1 ms 348 KB correct
3 Correct 1 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 600 KB correct
9 Correct 1 ms 344 KB correct
10 Correct 1 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 1 ms 348 KB correct
13 Correct 1 ms 348 KB correct
14 Correct 8 ms 348 KB correct
15 Correct 8 ms 344 KB correct
16 Correct 8 ms 344 KB correct
17 Correct 6 ms 348 KB correct
18 Correct 1 ms 348 KB correct
19 Correct 6 ms 348 KB correct
20 Correct 5 ms 548 KB correct
21 Correct 5 ms 348 KB correct
22 Correct 3 ms 348 KB correct
23 Correct 3 ms 348 KB correct
24 Correct 3 ms 520 KB correct
25 Correct 1 ms 348 KB correct
26 Correct 3 ms 348 KB correct
27 Correct 4 ms 348 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 1 ms 344 KB correct
30 Correct 3 ms 348 KB correct
31 Correct 3 ms 348 KB correct
32 Correct 3 ms 348 KB correct
33 Correct 3 ms 348 KB correct
34 Correct 1815 ms 2072 KB correct
35 Correct 1731 ms 2140 KB correct
36 Correct 796 ms 2072 KB correct
37 Correct 8 ms 344 KB correct
38 Correct 1794 ms 2336 KB correct
39 Correct 1274 ms 2080 KB correct
40 Correct 861 ms 2076 KB correct
41 Incorrect 1850 ms 2332 KB WA in grader: NO
42 Halted 0 ms 0 KB -