답안 #1029154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029154 2024-07-20T13:02:25 Z AmirAli_H1 Simurgh (IOI17_simurgh) C++17
51 / 100
91 ms 4432 KB
// In the name of Allah
#include <bits/stdc++.h>
#include "simurgh.h"
using namespace std;

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 500 + 7;

int n, m;
vector<int> adj[maxn];
int mark[maxn], par[maxn];
int markx[maxn], M[maxn][maxn];
int ind[maxn][maxn], markw[maxn];
vector<int> res, ls, lsx, vc;

void dfs(int v) {
	markw[v] = 1;
	for (int u : adj[v]) {
		if (!markw[u]) {
			ls.pb(ind[v][u]);
			dfs(u);
		}
	}
}

bool okx(int v) {
	ls.clear();
	for (int i = 0; i < n; i++) markw[i] = mark[i];
	markw[v] = 1;
	dfs(0); int T = -len(ls);
	for (int u = 0; u < n; u++) {
		if (u == v) continue;
		if (mark[u]) ls.pb(ind[u][par[u]]);
		else T++;
	}
	return (T == 1);
}

void checkx(int v) {
	int t = 0, j = -1;
	for (int u = 0; u < n; u++) {
		if (mark[u]) continue;
		if (M[v][u]) {
			t++; j = u;
		}
	}
	if (t == 1) {
		par[v] = j;
		mark[v] = 1;
	}
}

void check(int v) {
	if (!markx[v] && okx(v)) {
		bool flag = 0;
		int mx = -1; vc.clear();
		for (int u : adj[v]) {
			if (mark[u]) continue;
			if (markx[u]) {
				if (flag || !M[u][v]) continue;
				else flag = 1;
			}
			lsx.clear(); lsx = ls;
			lsx.pb(ind[u][v]);
			int R = count_common_roads(lsx);
			if (R > mx) {
				mx = R;
				vc.clear(); vc.pb(u);
			}
			else if (R == mx) vc.pb(u);
		}
		for (int u : vc) M[v][u] = M[u][v] = 1;
		markx[v] = 1;
	}
	if (markx[v]) checkx(v);
}

vector<int> find_roads(int Nx, vector<int> ux, vector<int> vx) {
	n = Nx; m = len(ux);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) ind[i][j] = -1;
	}
	for (int i = 0; i < m; i++) {
		int u = ux[i], v = vx[i];
		adj[u].pb(v); adj[v].pb(u);
		ind[u][v] = ind[v][u] = i;
	}
	
	while (true) {
		int T = 0;
		for (int v = 1; v < n; v++) {
			if (!mark[v]) {
				check(v);
				T += 1;
			}
		}
		if (T == 0) break;
	}
	
	for (int v = 1; v < n; v++) {
		int u = par[v];
		res.pb(ind[u][v]);
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 456 KB correct
5 Correct 0 ms 344 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 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 344 KB correct
13 Correct 0 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 456 KB correct
5 Correct 0 ms 344 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 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 344 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 1 ms 604 KB correct
15 Correct 1 ms 604 KB correct
16 Correct 2 ms 604 KB correct
17 Correct 1 ms 604 KB correct
18 Correct 1 ms 604 KB correct
19 Correct 1 ms 604 KB correct
20 Correct 1 ms 856 KB correct
21 Correct 1 ms 604 KB correct
22 Correct 1 ms 468 KB correct
23 Correct 1 ms 604 KB correct
24 Correct 1 ms 604 KB correct
25 Correct 1 ms 604 KB correct
26 Correct 1 ms 604 KB correct
27 Correct 1 ms 464 KB correct
28 Correct 1 ms 604 KB correct
29 Correct 1 ms 604 KB correct
30 Correct 1 ms 604 KB correct
31 Correct 1 ms 604 KB correct
32 Correct 1 ms 604 KB correct
33 Correct 1 ms 604 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 456 KB correct
5 Correct 0 ms 344 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 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 344 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 1 ms 604 KB correct
15 Correct 1 ms 604 KB correct
16 Correct 2 ms 604 KB correct
17 Correct 1 ms 604 KB correct
18 Correct 1 ms 604 KB correct
19 Correct 1 ms 604 KB correct
20 Correct 1 ms 856 KB correct
21 Correct 1 ms 604 KB correct
22 Correct 1 ms 468 KB correct
23 Correct 1 ms 604 KB correct
24 Correct 1 ms 604 KB correct
25 Correct 1 ms 604 KB correct
26 Correct 1 ms 604 KB correct
27 Correct 1 ms 464 KB correct
28 Correct 1 ms 604 KB correct
29 Correct 1 ms 604 KB correct
30 Correct 1 ms 604 KB correct
31 Correct 1 ms 604 KB correct
32 Correct 1 ms 604 KB correct
33 Correct 1 ms 604 KB correct
34 Correct 87 ms 2140 KB correct
35 Correct 90 ms 2388 KB correct
36 Correct 59 ms 2128 KB correct
37 Correct 6 ms 1480 KB correct
38 Correct 91 ms 2132 KB correct
39 Correct 74 ms 2140 KB correct
40 Correct 58 ms 2128 KB correct
41 Correct 84 ms 2136 KB correct
42 Correct 80 ms 2132 KB correct
43 Correct 47 ms 1880 KB correct
44 Correct 44 ms 1784 KB correct
45 Correct 45 ms 1752 KB correct
46 Correct 33 ms 1624 KB correct
47 Correct 16 ms 1492 KB correct
48 Correct 3 ms 1372 KB correct
49 Correct 6 ms 1372 KB correct
50 Correct 16 ms 1628 KB correct
51 Correct 44 ms 1872 KB correct
52 Correct 46 ms 1824 KB correct
53 Correct 34 ms 1624 KB correct
54 Correct 46 ms 1864 KB correct
55 Correct 43 ms 1872 KB correct
56 Correct 47 ms 1808 KB correct
57 Correct 42 ms 1880 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 344 KB correct
3 Incorrect 65 ms 4432 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 0 ms 456 KB correct
5 Correct 0 ms 344 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 0 ms 348 KB correct
11 Correct 0 ms 348 KB correct
12 Correct 1 ms 344 KB correct
13 Correct 0 ms 348 KB correct
14 Correct 1 ms 604 KB correct
15 Correct 1 ms 604 KB correct
16 Correct 2 ms 604 KB correct
17 Correct 1 ms 604 KB correct
18 Correct 1 ms 604 KB correct
19 Correct 1 ms 604 KB correct
20 Correct 1 ms 856 KB correct
21 Correct 1 ms 604 KB correct
22 Correct 1 ms 468 KB correct
23 Correct 1 ms 604 KB correct
24 Correct 1 ms 604 KB correct
25 Correct 1 ms 604 KB correct
26 Correct 1 ms 604 KB correct
27 Correct 1 ms 464 KB correct
28 Correct 1 ms 604 KB correct
29 Correct 1 ms 604 KB correct
30 Correct 1 ms 604 KB correct
31 Correct 1 ms 604 KB correct
32 Correct 1 ms 604 KB correct
33 Correct 1 ms 604 KB correct
34 Correct 87 ms 2140 KB correct
35 Correct 90 ms 2388 KB correct
36 Correct 59 ms 2128 KB correct
37 Correct 6 ms 1480 KB correct
38 Correct 91 ms 2132 KB correct
39 Correct 74 ms 2140 KB correct
40 Correct 58 ms 2128 KB correct
41 Correct 84 ms 2136 KB correct
42 Correct 80 ms 2132 KB correct
43 Correct 47 ms 1880 KB correct
44 Correct 44 ms 1784 KB correct
45 Correct 45 ms 1752 KB correct
46 Correct 33 ms 1624 KB correct
47 Correct 16 ms 1492 KB correct
48 Correct 3 ms 1372 KB correct
49 Correct 6 ms 1372 KB correct
50 Correct 16 ms 1628 KB correct
51 Correct 44 ms 1872 KB correct
52 Correct 46 ms 1824 KB correct
53 Correct 34 ms 1624 KB correct
54 Correct 46 ms 1864 KB correct
55 Correct 43 ms 1872 KB correct
56 Correct 47 ms 1808 KB correct
57 Correct 42 ms 1880 KB correct
58 Correct 0 ms 344 KB correct
59 Correct 0 ms 344 KB correct
60 Incorrect 65 ms 4432 KB WA in grader: NO
61 Halted 0 ms 0 KB -