Submission #293138

# Submission time Handle Problem Language Result Execution time Memory
293138 2020-09-07T16:45:27 Z amoo_safar Simurgh (IOI17_simurgh) C++17
51 / 100
220 ms 4584 KB
#include "simurgh.h"

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int N = 500 + 10;

vector<pii> G[N], H[N];
int mk[N], E[N], par[N], dep[N];

vector<int> R;

void DFS1(int u, int d = 0){
	mk[u] = 1;
	dep[u] = d;
	for(auto [adj, id] : G[u]){
		if(!mk[adj]){
			R.pb(id);
			par[adj] = u;
			DFS1(adj, d + 1);
			E[adj] = id;
			//cerr << "^ " << u << ' ' << adj << '\n';
		}
	}
}
ll f;
int mp[N * N];

int Ask(int rm, int is){
	if(mp[rm] != -1) return mp[rm];
	vector<int> R2 = R;
	for(auto &x : R2) if(x == rm) x = is;
	mp[rm] = count_common_roads(R2);
	//cerr << "Ask " << rm << ' ' << is << ' ' << mp[{rm, is}] << '\n';
	return mp[rm];
}

int sta[N * N];

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	vector<int> r(n - 1);
	int m = u.size();
	for(int i = 0; i < m; i++){
		G[u[i]].pb({v[i], i});
		G[v[i]].pb({u[i], i});
	}
	DFS1(0, 0);
	f = count_common_roads(R);
	E[0] = -1;
	par[0] = -1;
	//cerr << "F : " << f << '\n';

	memset(mp, -1, sizeof mp);
	vector<int> X;
	for(int i = 0; i < m; i++){
		if(dep[u[i]] > dep[v[i]]) swap(u[i], v[i]);
		if(E[v[i]] == i) continue;
		//memset(mp, -1, sizeof mp);
		
		X.clear();
		int nw = v[i];
		////cerr << '\n';
		while(nw != u[i]){
			////cerr << "# " << nw << '\n';
			assert(nw != 0);
			X.pb(E[nw]);
			nw = par[nw];
		}
		//cerr << "& " << u[i] << ' ' << v[i] << '\n';
		//cerr << "!! ";
			//cerr << x << ' ';
		//cerr << '\n';

		int mn = f;
		bool flg = false;
		int res;
		//cerr << "MTF : " << f << '\n';
		for(auto x : X){
			if(sta[x] && flg){
				if(sta[x] == 2){
					mn = min(mn, res);
					mp[x] = res;
				} else {
					mp[x] = res + 1;
					mn = min(mn, res + 1);
				}
				continue;
			}
			if(sta[x] == 1){
				mn = min(mn, Ask(x, i));
				res = Ask(x, i) - 1;
				flg = true;
			} else if(sta[x] == 2){
				mn = min(mn, Ask(x, i));
				res = Ask(x, i);
				flg = true;
			} else {
				mn = min(mn, Ask(x, i));
			}
		}
		
		//cerr << "mn : " << mn << '\n';

		bool f2 = (f != mn);
		for(auto x : X) if(mn != Ask(x, i)) f2 = true;
		if(f2){
			if(f == mn) sta[i] = 2;
			else sta[i] = 1;
			for(auto x : X){
				if(sta[x] == 0){
					if(Ask(x, i) == mn) sta[x] = 2;
					else sta[x] = 1;
				}
			}
		} else {
			sta[i] = 1;
			for(auto x : X) sta[x] = 1;
		}

		//for(int j = 0; j < m; j++) //cerr << sta[j];
		//cerr << '\n';
		for(auto x : X) mp[x] = -1;
	}
	vector<int> res;
	for(int i = 0; i < m; i++) if(sta[i] != 1) res.pb(i);
	//for(auto x : res)
		//cerr << "% " << x << '\n';

	assert(((int) res.size()) == n - 1);
	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1384 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 1 ms 1408 KB correct
10 Correct 1 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 1 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1384 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 1 ms 1408 KB correct
10 Correct 1 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 1 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
14 Correct 4 ms 1408 KB correct
15 Correct 4 ms 1408 KB correct
16 Correct 4 ms 1408 KB correct
17 Correct 3 ms 1408 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 3 ms 1408 KB correct
20 Correct 3 ms 1408 KB correct
21 Correct 3 ms 1408 KB correct
22 Correct 2 ms 1408 KB correct
23 Correct 2 ms 1408 KB correct
24 Correct 2 ms 1408 KB correct
25 Correct 1 ms 1432 KB correct
26 Correct 2 ms 1408 KB correct
27 Correct 3 ms 1408 KB correct
28 Correct 2 ms 1408 KB correct
29 Correct 1 ms 1408 KB correct
30 Correct 2 ms 1408 KB correct
31 Correct 2 ms 1408 KB correct
32 Correct 2 ms 1408 KB correct
33 Correct 2 ms 1408 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1384 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 1 ms 1408 KB correct
10 Correct 1 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 1 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
14 Correct 4 ms 1408 KB correct
15 Correct 4 ms 1408 KB correct
16 Correct 4 ms 1408 KB correct
17 Correct 3 ms 1408 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 3 ms 1408 KB correct
20 Correct 3 ms 1408 KB correct
21 Correct 3 ms 1408 KB correct
22 Correct 2 ms 1408 KB correct
23 Correct 2 ms 1408 KB correct
24 Correct 2 ms 1408 KB correct
25 Correct 1 ms 1432 KB correct
26 Correct 2 ms 1408 KB correct
27 Correct 3 ms 1408 KB correct
28 Correct 2 ms 1408 KB correct
29 Correct 1 ms 1408 KB correct
30 Correct 2 ms 1408 KB correct
31 Correct 2 ms 1408 KB correct
32 Correct 2 ms 1408 KB correct
33 Correct 2 ms 1408 KB correct
34 Correct 220 ms 2812 KB correct
35 Correct 207 ms 2680 KB correct
36 Correct 139 ms 2432 KB correct
37 Correct 10 ms 1408 KB correct
38 Correct 217 ms 2676 KB correct
39 Correct 179 ms 2680 KB correct
40 Correct 142 ms 2432 KB correct
41 Correct 213 ms 2696 KB correct
42 Correct 208 ms 2684 KB correct
43 Correct 112 ms 2176 KB correct
44 Correct 85 ms 1920 KB correct
45 Correct 95 ms 2048 KB correct
46 Correct 76 ms 1920 KB correct
47 Correct 32 ms 1664 KB correct
48 Correct 3 ms 1408 KB correct
49 Correct 10 ms 1408 KB correct
50 Correct 31 ms 1664 KB correct
51 Correct 97 ms 2040 KB correct
52 Correct 81 ms 1920 KB correct
53 Correct 72 ms 2040 KB correct
54 Correct 102 ms 2248 KB correct
55 Correct 114 ms 2048 KB correct
56 Correct 110 ms 2048 KB correct
57 Correct 108 ms 2084 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Incorrect 168 ms 4584 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1408 KB correct
2 Correct 1 ms 1408 KB correct
3 Correct 1 ms 1408 KB correct
4 Correct 1 ms 1408 KB correct
5 Correct 1 ms 1384 KB correct
6 Correct 1 ms 1408 KB correct
7 Correct 1 ms 1408 KB correct
8 Correct 1 ms 1408 KB correct
9 Correct 1 ms 1408 KB correct
10 Correct 1 ms 1408 KB correct
11 Correct 1 ms 1408 KB correct
12 Correct 1 ms 1408 KB correct
13 Correct 1 ms 1408 KB correct
14 Correct 4 ms 1408 KB correct
15 Correct 4 ms 1408 KB correct
16 Correct 4 ms 1408 KB correct
17 Correct 3 ms 1408 KB correct
18 Correct 2 ms 1408 KB correct
19 Correct 3 ms 1408 KB correct
20 Correct 3 ms 1408 KB correct
21 Correct 3 ms 1408 KB correct
22 Correct 2 ms 1408 KB correct
23 Correct 2 ms 1408 KB correct
24 Correct 2 ms 1408 KB correct
25 Correct 1 ms 1432 KB correct
26 Correct 2 ms 1408 KB correct
27 Correct 3 ms 1408 KB correct
28 Correct 2 ms 1408 KB correct
29 Correct 1 ms 1408 KB correct
30 Correct 2 ms 1408 KB correct
31 Correct 2 ms 1408 KB correct
32 Correct 2 ms 1408 KB correct
33 Correct 2 ms 1408 KB correct
34 Correct 220 ms 2812 KB correct
35 Correct 207 ms 2680 KB correct
36 Correct 139 ms 2432 KB correct
37 Correct 10 ms 1408 KB correct
38 Correct 217 ms 2676 KB correct
39 Correct 179 ms 2680 KB correct
40 Correct 142 ms 2432 KB correct
41 Correct 213 ms 2696 KB correct
42 Correct 208 ms 2684 KB correct
43 Correct 112 ms 2176 KB correct
44 Correct 85 ms 1920 KB correct
45 Correct 95 ms 2048 KB correct
46 Correct 76 ms 1920 KB correct
47 Correct 32 ms 1664 KB correct
48 Correct 3 ms 1408 KB correct
49 Correct 10 ms 1408 KB correct
50 Correct 31 ms 1664 KB correct
51 Correct 97 ms 2040 KB correct
52 Correct 81 ms 1920 KB correct
53 Correct 72 ms 2040 KB correct
54 Correct 102 ms 2248 KB correct
55 Correct 114 ms 2048 KB correct
56 Correct 110 ms 2048 KB correct
57 Correct 108 ms 2084 KB correct
58 Correct 1 ms 1408 KB correct
59 Correct 1 ms 1408 KB correct
60 Incorrect 168 ms 4584 KB WA in grader: NO
61 Halted 0 ms 0 KB -