Submission #805714

# Submission time Handle Problem Language Result Execution time Memory
805714 2023-08-03T21:11:59 Z Username4132 Simurgh (IOI17_simurgh) C++14
100 / 100
142 ms 7728 KB
#include "simurgh.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<cassert>
using namespace std;
using pii = pair<int, int>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back
#define F first
#define S second

int n, m, tm, base, esp[125010], pv[510], pe[510], tin[510];
bool vis[510];
pii edges[125010];
vector<int> ted;
vector<vector<int>> uns;
vector<pii> g[510];

void dfs(int v){
	tin[v]=tm++;
	vis[v]=true;
	for(pii to:g[v]) if(!vis[to.F]){
		pv[to.F]=v;
		pe[to.F]=to.S;
		ted.PB(to.S);
		dfs(to.F);
	}
}

int add_count(int r){
	int cou=base;
	vector<int> ask;
	forn(i, r){
		if(!uns[i].empty()) ask.PB(uns[i].back()), cou-=esp[ted[i]];
		else ask.PB(ted[i]);
	}
	forsn(i, r, n-1) ask.PB(ted[i]);
	return count_common_roads(ask) - cou;
}

void dfs2(int l, int r, int lv, int rv){
	if(lv==rv) return;
	if(r-l==1){
		esp[uns[l].back()]=1;
		return;
	}
	int mid = (l+r)>>1, value = add_count(mid);
	dfs2(l, mid, lv, value);
	dfs2(mid, r, value, rv);
}

vector<int> find_roads(int N, vector<int> u, vector<int> v) {
	int debug=0;
	n=N; m=u.size();
	forn(i, m){
		g[u[i]].PB({v[i], i});
		g[v[i]].PB({u[i], i});
		edges[i]={u[i], v[i]};
		esp[i]=-1;
	}
	dfs(0);
	sort(ted.begin(), ted.end());
	base = count_common_roads(ted);
	uns.resize(ted.size());

	forn(i, m){
		int a = edges[i].F, b = edges[i].S, know=-1;
		if(tin[a]<tin[b]) swap(a, b);
		if(pv[a]==b) continue;
		uns[lower_bound(ted.begin(), ted.end(), pe[a]) - ted.begin()].PB(i);
		vector<int> ed, res;
		int cur=a;
		while(cur!=b){
			int e = pe[cur];
			if(esp[e]!=-1) know=e;
			else{
				vector<int> tmp;
				for(int el:ted) if(el!=e) tmp.PB(el);
				tmp.PB(i);
				ed.PB(e);
				++debug;
				res.PB(count_common_roads(tmp));
			}
			cur = pv[cur];
		}
		if(ed.empty()) continue;
		if(know==-1){
			int mx = *max_element(res.begin(), res.end());
			mx = max(mx, base);
			forn(j, ed.size()) esp[ed[j]]=(res[j]!=mx);
		}
		else{
			vector<int> tmp;
			for(int el:ted) if(el!=know) tmp.PB(el);
			tmp.PB(i);
			++debug;
			int value = count_common_roads(tmp);
			forn(j, ed.size()) esp[ed[j]]=esp[know]^(res[j]!=value);
		}
	}

	assert(debug < 2*n + 5);
	for(int e:ted) if(esp[e]==-1) esp[e]=1;
	bool cont=true;
	while(cont){
		int rv = add_count(n-1);
		dfs2(0, n-1, 0, rv);
		cont=false;
		forn(i, n-1){
			if(!uns[i].empty()) uns[i].pop_back();
			cont|=!uns[i].empty();
		}
	}

	vector<int> ret;
	forn(i, m) if(esp[i]==1) ret.PB(i);
	assert((int)ret.size()==n-1);
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 1 ms 340 KB correct
15 Correct 1 ms 340 KB correct
16 Correct 1 ms 340 KB correct
17 Correct 1 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 0 ms 340 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 1 ms 340 KB correct
15 Correct 1 ms 340 KB correct
16 Correct 1 ms 340 KB correct
17 Correct 1 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 0 ms 340 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 20 ms 1808 KB correct
35 Correct 20 ms 2008 KB correct
36 Correct 16 ms 1620 KB correct
37 Correct 5 ms 324 KB correct
38 Correct 23 ms 2024 KB correct
39 Correct 18 ms 1768 KB correct
40 Correct 15 ms 1660 KB correct
41 Correct 21 ms 2004 KB correct
42 Correct 20 ms 2020 KB correct
43 Correct 10 ms 1400 KB correct
44 Correct 8 ms 1108 KB correct
45 Correct 8 ms 1204 KB correct
46 Correct 8 ms 980 KB correct
47 Correct 4 ms 676 KB correct
48 Correct 2 ms 320 KB correct
49 Correct 3 ms 340 KB correct
50 Correct 5 ms 596 KB correct
51 Correct 9 ms 1108 KB correct
52 Correct 8 ms 1108 KB correct
53 Correct 8 ms 972 KB correct
54 Correct 9 ms 1364 KB correct
55 Correct 10 ms 1224 KB correct
56 Correct 10 ms 1108 KB correct
57 Correct 9 ms 1108 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 67 ms 4784 KB correct
4 Correct 115 ms 7468 KB correct
5 Correct 117 ms 7568 KB correct
6 Correct 113 ms 7508 KB correct
7 Correct 142 ms 7604 KB correct
8 Correct 116 ms 7504 KB correct
9 Correct 120 ms 7596 KB correct
10 Correct 117 ms 7620 KB correct
11 Correct 114 ms 7620 KB correct
12 Correct 114 ms 7508 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 114 ms 7532 KB correct
15 Correct 116 ms 7552 KB correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB correct
2 Correct 1 ms 212 KB correct
3 Correct 0 ms 212 KB correct
4 Correct 1 ms 212 KB correct
5 Correct 0 ms 212 KB correct
6 Correct 0 ms 212 KB correct
7 Correct 0 ms 212 KB correct
8 Correct 0 ms 212 KB correct
9 Correct 0 ms 212 KB correct
10 Correct 1 ms 212 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 1 ms 340 KB correct
15 Correct 1 ms 340 KB correct
16 Correct 1 ms 340 KB correct
17 Correct 1 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 340 KB correct
21 Correct 1 ms 340 KB correct
22 Correct 1 ms 340 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 0 ms 340 KB correct
26 Correct 1 ms 340 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 20 ms 1808 KB correct
35 Correct 20 ms 2008 KB correct
36 Correct 16 ms 1620 KB correct
37 Correct 5 ms 324 KB correct
38 Correct 23 ms 2024 KB correct
39 Correct 18 ms 1768 KB correct
40 Correct 15 ms 1660 KB correct
41 Correct 21 ms 2004 KB correct
42 Correct 20 ms 2020 KB correct
43 Correct 10 ms 1400 KB correct
44 Correct 8 ms 1108 KB correct
45 Correct 8 ms 1204 KB correct
46 Correct 8 ms 980 KB correct
47 Correct 4 ms 676 KB correct
48 Correct 2 ms 320 KB correct
49 Correct 3 ms 340 KB correct
50 Correct 5 ms 596 KB correct
51 Correct 9 ms 1108 KB correct
52 Correct 8 ms 1108 KB correct
53 Correct 8 ms 972 KB correct
54 Correct 9 ms 1364 KB correct
55 Correct 10 ms 1224 KB correct
56 Correct 10 ms 1108 KB correct
57 Correct 9 ms 1108 KB correct
58 Correct 0 ms 212 KB correct
59 Correct 1 ms 212 KB correct
60 Correct 67 ms 4784 KB correct
61 Correct 115 ms 7468 KB correct
62 Correct 117 ms 7568 KB correct
63 Correct 113 ms 7508 KB correct
64 Correct 142 ms 7604 KB correct
65 Correct 116 ms 7504 KB correct
66 Correct 120 ms 7596 KB correct
67 Correct 117 ms 7620 KB correct
68 Correct 114 ms 7620 KB correct
69 Correct 114 ms 7508 KB correct
70 Correct 0 ms 212 KB correct
71 Correct 114 ms 7532 KB correct
72 Correct 116 ms 7552 KB correct
73 Correct 1 ms 212 KB correct
74 Correct 114 ms 7556 KB correct
75 Correct 111 ms 7360 KB correct
76 Correct 45 ms 2996 KB correct
77 Correct 113 ms 7620 KB correct
78 Correct 115 ms 7524 KB correct
79 Correct 122 ms 7728 KB correct
80 Correct 128 ms 7360 KB correct
81 Correct 100 ms 6728 KB correct
82 Correct 111 ms 7496 KB correct
83 Correct 70 ms 4212 KB correct
84 Correct 52 ms 5132 KB correct
85 Correct 46 ms 4720 KB correct
86 Correct 33 ms 3116 KB correct
87 Correct 24 ms 2592 KB correct
88 Correct 20 ms 1836 KB correct
89 Correct 20 ms 1764 KB correct
90 Correct 17 ms 1596 KB correct
91 Correct 8 ms 468 KB correct
92 Correct 6 ms 340 KB correct
93 Correct 49 ms 4776 KB correct
94 Correct 32 ms 3192 KB correct
95 Correct 31 ms 3144 KB correct
96 Correct 19 ms 1788 KB correct
97 Correct 20 ms 1848 KB correct
98 Correct 25 ms 2624 KB correct
99 Correct 21 ms 1876 KB correct
100 Correct 11 ms 724 KB correct
101 Correct 5 ms 340 KB correct
102 Correct 52 ms 3996 KB correct
103 Correct 53 ms 3916 KB correct
104 Correct 52 ms 3972 KB correct
105 Correct 52 ms 3952 KB correct