답안 #721582

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
721582 2023-04-11T04:56:41 Z minhcool Simurgh (IOI17_simurgh) C++17
51 / 100
3000 ms 11056 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
 
#define save savee
#define find findd
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 1005 + 5;
 
 
int n, m, a[N];
 
int count(vector<int> v){
  //if((double)clock() / (double)CLOCKS_PER_SEC >= 1.0) exit(0);
//	for(auto it : v) cout << it << " ";
//	cout << "\n";
	//assert(v.size() == (n - 1));
	if(v.size() != (n - 1)) exit(0);
	return count_common_roads(v);
}
 
set<int> Adj[N];
 
bool vis[N * N];
int cnt;
int tim[N * N], low[N * N];
int edg[N * N];// backedge that correspond to low
 
int ind[N][N], dep[N * N];
bool find[N * N], answ[N * N], bri[N * N];
 
int par[N * N];
 
vector<int> ask;
 
void dfs(int u, int p){
  //if((double)clock() / (double)CLOCKS_PER_SEC >= 1.0) exit(0);
	vis[u] = 1;
	cnt++;
	tim[u] = low[u] = cnt;
	edg[u] = -1;
	for(auto v : Adj[u]){
		if(!vis[v]){
			ask.pb(ind[u][v]);
			dep[v] = dep[u] + 1;
			par[v] = u;
			dfs(v, u);
			if(low[u] > low[v]){
				low[u] = low[v];
				edg[u] = edg[v];
			}
			if(low[v] > tim[u]){
				find[ind[u][v]] = answ[ind[u][v]] = bri[ind[u][v]] = 1;
			}
		}
		else if(v != p){
			if(low[u] > tim[v]){
				low[u] = tim[v];
				edg[u] = ind[u][v];
			}
		}
	}
}
 
vector<int> roads;
 
bool get(int u, int need){
  //if((double)clock() / (double)CLOCKS_PER_SEC >= 1.0) exit(0);
	vis[u] = 1;
	if(u == need) return 1;
	for(auto v : Adj[u]){
		if(vis[v]) continue;
		if(get(v, need)){
			roads.pb(ind[u][v]);
			return 1;
		}
	}
    return 0;
}
 
int save[N * N];
 
vector<int> oth;
 
void find_oth_edg(int u){
 // if((double)clock() / (double)CLOCKS_PER_SEC >= 1.0) exit(0);
	vis[u] = 1;
	for(auto v : Adj[u]){
		if(vis[v]) continue;
		oth.pb(ind[u][v]);
		find_oth_edg(v);
	}
}
 
vector<int> find_roads(int n_, vector<int> u, vector<int> v){
	//exit(0);
	n = n_, m = u.size();
//	cout << u.size() << " " << v.size() << "\n";
	for(int i = 0; i < m; i++){
	//	assert(u.size() > i);
	//	assert(v.size() > i);
	//	cout << u[i] << " " << v[i] << "\n";
	//	continue;
		Adj[u[i]].insert(v[i]);
		Adj[v[i]].insert(u[i]);
		//cout << u[i] << " " << v[i] << "\n";
	//	continue;
		ind[u[i]][v[i]] = ind[v[i]][u[i]] = i;
	}
	//exit(0);
	dfs(0, 0);
	for(int i = 0; i < m; i++){
		if(bri[i]){
		//	cout << i << "\n";
			Adj[u[i]].erase(v[i]);
			Adj[v[i]].erase(u[i]);
		}
	}
	//exit(0);
	for(int i = 0; i < n; i++) vis[i] = 0;
	cnt = 0;
	ask.clear();
	for(int i = 0; i < n; i++){
		if(!vis[i]){
			dep[i] = 0;
		//	if(n > 7) continue;
			dfs(i, i);
		}
	}
//	exit(0);
	for(auto it : ask){
		if(find[it]) continue;
		//if(n > 7) continue;
		int a = u[it], b = v[it];
		if(par[b] != a) swap(a, b);
	//	cout << a << " " << b << " " << par[a] << " " << par[b] << "\n";
	//	if(par[a] != b && par[b] != a) cout << "OK\n";
		if(par[b] != a) exit(0);
	//	cout << par[17] << " " << par[18] << "\n";
		//continue;
		for(int i = 0; i < n; i++) vis[i] = 0;
		Adj[a].erase(b), Adj[b].erase(a);
		roads.clear();
	//	if(n > 7) continue;
		get(b, a);
		roads.pb(it);
	//	cout << "OK " << it << "\n";
	//	for(auto it2 : roads) cout << it2 << " ";
	//	cout << "\n";
		for(int i = 0; i < n; i++) vis[i] = 0;
		for(int i = 0; i < m; i++){
			if(bri[i]){
				Adj[u[i]].insert(v[i]);
				Adj[v[i]].insert(u[i]);
			}
		}
		for(auto it2 : roads){
			vis[u[it2]] = vis[v[it2]] = 1;
		}
		oth.clear();
		//if(n > 7) continue;
		// finding other edges apart from the cycle
		for(auto it2 : roads){
			find_oth_edg(u[it2]);
			find_oth_edg(v[it2]);
		}
		int ind = -1;
		for(auto it2 : roads) if(find[it2]) ind = it2;
		if(ind >= 0){
			vector<int> askk;
			for(auto it : oth) askk.pb(it);
			for(auto it3 : roads) if(it3 != ind) askk.pb(it3);
			int val = count(askk);
			for(auto it2 : roads){
				if(findd[it2]) continue;
				findd[it2] = 1;
				vector<int> askk;
				for(auto it : oth) askk.pb(it);
				for(auto it3 : roads) if(it3 != it2) askk.pb(it3);
				int val2 = count(askk);
				answ[it2] = answ[ind] + (val - val2);
			}
		}
		else{
      //for(int i = 0; i < n; i++) if(!vis[i]) cout << "OK\n";
		for(auto it2 : roads){
		//	cout << "WTF\n";
			vector<int> askk;
			for(auto it : oth) askk.pb(it);
			for(auto it3 : roads) if(it2 != it3) askk.pb(it3);
			//for(auto it : askk) cout << it << " ";
		//	cout << "\n";
			//continue;
			save[it2] = count(askk);
		}
		int mn = 1e9, mx = -1e9;
		for(auto it2 : roads){
			mn = min(mn, save[it2]);
			mx = max(mx, save[it2]);
		}
        //if(n > 7) continue;
		if(mn == mx){// then everything equals to zero
			for(auto it2 : roads){
				find[it2] = 1;
				answ[it2] = 0;
			}
		}
		else{
			for(auto it2 : roads){
				find[it2] = 1;
				if(save[it2] == mn) answ[it2] = 1;
				else answ[it2] = 0;
			}
		}
		}
		for(int i = 0; i < m; i++){
			if(bri[i]){
				Adj[u[i]].erase(v[i]);
				Adj[v[i]].erase(u[i]);
			}
		}
	//	assert(par[b] == a);
	//	int c = u[edg[b]], d = v[edg[b]];
	}
  //	if(n > 7) exit(0);
	for(int i = 0; i < m; i++){
		if(bri[i]){
			Adj[u[i]].insert(v[i]);
			Adj[v[i]].insert(u[i]);
		}
	}
	vector<int> vv = ask;
	for(int i = 0; i < m; i++) if(bri[i]) vv.pb(i);
	int ori_ans = count(vv);
//	for(int i = 0; i < m; i++) cout << find[i] << " " << answ[i] << "\n";
	for(int i = 0; i < m; i++){
		if(find[i]) continue;
		find[i] = 1;
		int a = u[i], b = v[i];
		if(dep[a] > dep[b]) swap(a, b);
		int temp = ind[b][par[b]];
		vector<int> vv;
		for(int j = 0; j < m; j++) if(bri[j]) vv.pb(j);
		for(auto it : ask) if(it != temp) vv.pb(it);
		vv.pb(i);
		answ[i] = answ[temp] + (count(vv) - ori_ans);
	}
	vector<int> ans;
	//for(int i = 0; i < m; i++) cout << answ[i];
	//cout << "\n";
	for(int i = 0; i < m; i++) if(answ[i]) ans.pb(i);
	//assert(ans.size() == (n - 1));
	return ans;
}
 
/*
 
void process(){
	cin >> n;
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--) process();
}
*/

Compilation message

simurgh.cpp: In function 'int count(std::vector<int>)':
simurgh.cpp:26:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |  if(v.size() != (n - 1)) exit(0);
      |     ~~~~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 468 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 340 KB correct
6 Correct 0 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 368 KB correct
12 Correct 1 ms 340 KB correct
13 Correct 1 ms 372 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 468 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 340 KB correct
6 Correct 0 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 368 KB correct
12 Correct 1 ms 340 KB correct
13 Correct 1 ms 372 KB correct
14 Correct 9 ms 764 KB correct
15 Correct 9 ms 780 KB correct
16 Correct 9 ms 724 KB correct
17 Correct 7 ms 724 KB correct
18 Correct 2 ms 596 KB correct
19 Correct 7 ms 724 KB correct
20 Correct 7 ms 756 KB correct
21 Correct 6 ms 724 KB correct
22 Correct 5 ms 724 KB correct
23 Correct 4 ms 596 KB correct
24 Correct 4 ms 624 KB correct
25 Correct 1 ms 596 KB correct
26 Correct 4 ms 596 KB correct
27 Correct 4 ms 596 KB correct
28 Correct 2 ms 596 KB correct
29 Correct 1 ms 596 KB correct
30 Correct 3 ms 596 KB correct
31 Correct 4 ms 596 KB correct
32 Correct 3 ms 704 KB correct
33 Correct 4 ms 596 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 468 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 340 KB correct
6 Correct 0 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 368 KB correct
12 Correct 1 ms 340 KB correct
13 Correct 1 ms 372 KB correct
14 Correct 9 ms 764 KB correct
15 Correct 9 ms 780 KB correct
16 Correct 9 ms 724 KB correct
17 Correct 7 ms 724 KB correct
18 Correct 2 ms 596 KB correct
19 Correct 7 ms 724 KB correct
20 Correct 7 ms 756 KB correct
21 Correct 6 ms 724 KB correct
22 Correct 5 ms 724 KB correct
23 Correct 4 ms 596 KB correct
24 Correct 4 ms 624 KB correct
25 Correct 1 ms 596 KB correct
26 Correct 4 ms 596 KB correct
27 Correct 4 ms 596 KB correct
28 Correct 2 ms 596 KB correct
29 Correct 1 ms 596 KB correct
30 Correct 3 ms 596 KB correct
31 Correct 4 ms 596 KB correct
32 Correct 3 ms 704 KB correct
33 Correct 4 ms 596 KB correct
34 Correct 2931 ms 4804 KB correct
35 Correct 2723 ms 4696 KB correct
36 Correct 1340 ms 3800 KB correct
37 Correct 11 ms 1492 KB correct
38 Correct 2922 ms 4844 KB correct
39 Correct 2134 ms 4292 KB correct
40 Correct 1333 ms 3684 KB correct
41 Correct 2862 ms 4808 KB correct
42 Correct 2963 ms 4796 KB correct
43 Correct 904 ms 3228 KB correct
44 Correct 622 ms 2980 KB correct
45 Correct 798 ms 3220 KB correct
46 Correct 487 ms 2644 KB correct
47 Correct 113 ms 1996 KB correct
48 Correct 6 ms 1440 KB correct
49 Correct 17 ms 1492 KB correct
50 Correct 109 ms 1956 KB correct
51 Correct 778 ms 3100 KB correct
52 Correct 587 ms 2940 KB correct
53 Correct 469 ms 2644 KB correct
54 Correct 922 ms 3328 KB correct
55 Correct 768 ms 3124 KB correct
56 Correct 784 ms 3120 KB correct
57 Correct 782 ms 3148 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 468 KB correct
3 Execution timed out 3059 ms 11056 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 468 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 340 KB correct
6 Correct 0 ms 340 KB correct
7 Correct 1 ms 340 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 340 KB correct
10 Correct 1 ms 340 KB correct
11 Correct 1 ms 368 KB correct
12 Correct 1 ms 340 KB correct
13 Correct 1 ms 372 KB correct
14 Correct 9 ms 764 KB correct
15 Correct 9 ms 780 KB correct
16 Correct 9 ms 724 KB correct
17 Correct 7 ms 724 KB correct
18 Correct 2 ms 596 KB correct
19 Correct 7 ms 724 KB correct
20 Correct 7 ms 756 KB correct
21 Correct 6 ms 724 KB correct
22 Correct 5 ms 724 KB correct
23 Correct 4 ms 596 KB correct
24 Correct 4 ms 624 KB correct
25 Correct 1 ms 596 KB correct
26 Correct 4 ms 596 KB correct
27 Correct 4 ms 596 KB correct
28 Correct 2 ms 596 KB correct
29 Correct 1 ms 596 KB correct
30 Correct 3 ms 596 KB correct
31 Correct 4 ms 596 KB correct
32 Correct 3 ms 704 KB correct
33 Correct 4 ms 596 KB correct
34 Correct 2931 ms 4804 KB correct
35 Correct 2723 ms 4696 KB correct
36 Correct 1340 ms 3800 KB correct
37 Correct 11 ms 1492 KB correct
38 Correct 2922 ms 4844 KB correct
39 Correct 2134 ms 4292 KB correct
40 Correct 1333 ms 3684 KB correct
41 Correct 2862 ms 4808 KB correct
42 Correct 2963 ms 4796 KB correct
43 Correct 904 ms 3228 KB correct
44 Correct 622 ms 2980 KB correct
45 Correct 798 ms 3220 KB correct
46 Correct 487 ms 2644 KB correct
47 Correct 113 ms 1996 KB correct
48 Correct 6 ms 1440 KB correct
49 Correct 17 ms 1492 KB correct
50 Correct 109 ms 1956 KB correct
51 Correct 778 ms 3100 KB correct
52 Correct 587 ms 2940 KB correct
53 Correct 469 ms 2644 KB correct
54 Correct 922 ms 3328 KB correct
55 Correct 768 ms 3124 KB correct
56 Correct 784 ms 3120 KB correct
57 Correct 782 ms 3148 KB correct
58 Correct 1 ms 340 KB correct
59 Correct 1 ms 468 KB correct
60 Execution timed out 3059 ms 11056 KB Time limit exceeded
61 Halted 0 ms 0 KB -