답안 #298732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
298732 2020-09-13T21:58:42 Z keko37 Simurgh (IOI17_simurgh) C++14
51 / 100
153 ms 4984 KB
#include<bits/stdc++.h>
#include "simurgh.h"

using namespace std;

typedef vector <int> vi;
typedef pair <int, int> pi;

const int MAXN = 505;
const int MAXM = 150005;

int n, m, uk;
int ea[MAXM], eb[MAXM], be[MAXM], pos[MAXM], sol[MAXM];
int bio[MAXN], par[MAXN], pe[MAXN], dub[MAXN];
int tmp[MAXN];
vector <pi> v[MAXN];
vi span;

void dfs (int x) {
	bio[x] = 1;
	for (auto pp : v[x]) {
		int sus = pp.first, ind = pp.second;
		if (sus == par[x]) continue;
		if (bio[sus]) {
			be[ind] = 1;
			continue;
		}
		par[sus] = x;
		dub[sus] = 1 + dub[x];
		pe[sus] = ind;
		pos[ind] = span.size();
		span.push_back(ind);
		dfs(sus);
	}
}

void obradi_back (int ind) {
	if (dub[ea[ind]] < dub[eb[ind]]) swap(ea[ind], eb[ind]);
	int lo = ea[ind], hi = eb[ind];
	vi cyc;
	bool naso = 0;
	while (lo != hi) {
		if (sol[pe[lo]] != -1) {
			naso = 1;
			break;
		}
		cyc.push_back(pe[lo]);
		lo = par[lo];
	}
	if (naso) {
		span[pos[pe[lo]]] = ind;
		if (count_common_roads(span) == uk) {
			sol[ind] = sol[pe[lo]];
		} else {
			sol[ind] = !sol[pe[lo]];
		}
		span[pos[pe[lo]]] = pe[lo];
	} else {
		int mn = uk, mx = uk;
		for (int i = 0; i < cyc.size(); i++) {
			span[pos[cyc[i]]] = ind;
			tmp[i] = count_common_roads(span);
			mx = max(mx, tmp[i]);
			mn = min(mn, tmp[i]);
			span[pos[cyc[i]]] = cyc[i];
		}
		if (mn == mx) {
			for (int i = 0; i < cyc.size(); i++) {
				sol[cyc[i]] = 0;
			}
			sol[ind] = 0;
		} else {
			for (int i = 0; i < cyc.size(); i++) {
				if (tmp[i] == mn) sol[cyc[i]] = 1; else sol[cyc[i]] = 0;
			}
			if (uk == mn) sol[ind] = 1; else sol[ind] = 0;
		}
	}
	lo = ea[ind];
	while (lo != hi) {
		if (sol[pe[lo]] == -1) {
			span[pos[pe[lo]]] = ind;
			if (count_common_roads(span) == uk) {
				sol[pe[lo]] = sol[ind];
			} else {
				sol[pe[lo]] = !sol[ind];
			}
			span[pos[pe[lo]]] = pe[lo];
		}
		lo = par[lo];
	}
}

vi find_roads (int N, vi U, vi V) {
	n = N; m = U.size();
	for (int i = 0; i < m; i++) {
		ea[i] = U[i], eb[i] = V[i];
		v[U[i]].push_back({V[i], i});
		v[V[i]].push_back({U[i], i});
	}
	dfs(0);
	par[0] = -1;
	uk = count_common_roads(span);
	memset(sol, -1, sizeof sol);
	for (int i = 0; i < m; i++) {
		if (be[i] == 1) {
			obradi_back(i);
		}
	}
	vi ans;
	for (int i = 0; i < m; i++) {
		if (sol[i] == 1 || sol[i] == -1) ans.push_back(i);
	}
	return ans;
}





Compilation message

simurgh.cpp: In function 'void obradi_back(int)':
simurgh.cpp:60:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for (int i = 0; i < cyc.size(); i++) {
      |                   ~~^~~~~~~~~~~~
simurgh.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |    for (int i = 0; i < cyc.size(); i++) {
      |                    ~~^~~~~~~~~~~~
simurgh.cpp:73:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |    for (int i = 0; i < cyc.size(); i++) {
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 896 KB correct
2 Correct 1 ms 1024 KB correct
3 Correct 1 ms 896 KB correct
4 Correct 1 ms 896 KB correct
5 Correct 1 ms 896 KB correct
6 Correct 1 ms 896 KB correct
7 Correct 1 ms 896 KB correct
8 Correct 1 ms 896 KB correct
9 Correct 1 ms 896 KB correct
10 Correct 1 ms 896 KB correct
11 Correct 1 ms 896 KB correct
12 Correct 1 ms 896 KB correct
13 Correct 1 ms 896 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 896 KB correct
2 Correct 1 ms 1024 KB correct
3 Correct 1 ms 896 KB correct
4 Correct 1 ms 896 KB correct
5 Correct 1 ms 896 KB correct
6 Correct 1 ms 896 KB correct
7 Correct 1 ms 896 KB correct
8 Correct 1 ms 896 KB correct
9 Correct 1 ms 896 KB correct
10 Correct 1 ms 896 KB correct
11 Correct 1 ms 896 KB correct
12 Correct 1 ms 896 KB correct
13 Correct 1 ms 896 KB correct
14 Correct 3 ms 1024 KB correct
15 Correct 2 ms 1152 KB correct
16 Correct 3 ms 1024 KB correct
17 Correct 2 ms 1024 KB correct
18 Correct 1 ms 1024 KB correct
19 Correct 2 ms 1024 KB correct
20 Correct 2 ms 1024 KB correct
21 Correct 2 ms 1024 KB correct
22 Correct 2 ms 1024 KB correct
23 Correct 2 ms 1024 KB correct
24 Correct 2 ms 1024 KB correct
25 Correct 1 ms 896 KB correct
26 Correct 2 ms 1024 KB correct
27 Correct 2 ms 1024 KB correct
28 Correct 1 ms 1024 KB correct
29 Correct 1 ms 896 KB correct
30 Correct 2 ms 1024 KB correct
31 Correct 2 ms 1024 KB correct
32 Correct 2 ms 1024 KB correct
33 Correct 2 ms 1024 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 896 KB correct
2 Correct 1 ms 1024 KB correct
3 Correct 1 ms 896 KB correct
4 Correct 1 ms 896 KB correct
5 Correct 1 ms 896 KB correct
6 Correct 1 ms 896 KB correct
7 Correct 1 ms 896 KB correct
8 Correct 1 ms 896 KB correct
9 Correct 1 ms 896 KB correct
10 Correct 1 ms 896 KB correct
11 Correct 1 ms 896 KB correct
12 Correct 1 ms 896 KB correct
13 Correct 1 ms 896 KB correct
14 Correct 3 ms 1024 KB correct
15 Correct 2 ms 1152 KB correct
16 Correct 3 ms 1024 KB correct
17 Correct 2 ms 1024 KB correct
18 Correct 1 ms 1024 KB correct
19 Correct 2 ms 1024 KB correct
20 Correct 2 ms 1024 KB correct
21 Correct 2 ms 1024 KB correct
22 Correct 2 ms 1024 KB correct
23 Correct 2 ms 1024 KB correct
24 Correct 2 ms 1024 KB correct
25 Correct 1 ms 896 KB correct
26 Correct 2 ms 1024 KB correct
27 Correct 2 ms 1024 KB correct
28 Correct 1 ms 1024 KB correct
29 Correct 1 ms 896 KB correct
30 Correct 2 ms 1024 KB correct
31 Correct 2 ms 1024 KB correct
32 Correct 2 ms 1024 KB correct
33 Correct 2 ms 1024 KB correct
34 Correct 141 ms 2680 KB correct
35 Correct 138 ms 2432 KB correct
36 Correct 100 ms 2176 KB correct
37 Correct 7 ms 1024 KB correct
38 Correct 142 ms 2560 KB correct
39 Correct 122 ms 2304 KB correct
40 Correct 96 ms 2176 KB correct
41 Correct 153 ms 2432 KB correct
42 Correct 139 ms 2432 KB correct
43 Correct 72 ms 1920 KB correct
44 Correct 56 ms 1664 KB correct
45 Correct 69 ms 1792 KB correct
46 Correct 57 ms 1536 KB correct
47 Correct 25 ms 1280 KB correct
48 Correct 3 ms 1024 KB correct
49 Correct 8 ms 1024 KB correct
50 Correct 24 ms 1280 KB correct
51 Correct 70 ms 1784 KB correct
52 Correct 60 ms 1748 KB correct
53 Correct 52 ms 1536 KB correct
54 Correct 78 ms 1920 KB correct
55 Correct 69 ms 1792 KB correct
56 Correct 71 ms 1792 KB correct
57 Correct 72 ms 1912 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 896 KB correct
2 Correct 1 ms 896 KB correct
3 Incorrect 117 ms 4984 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 896 KB correct
2 Correct 1 ms 1024 KB correct
3 Correct 1 ms 896 KB correct
4 Correct 1 ms 896 KB correct
5 Correct 1 ms 896 KB correct
6 Correct 1 ms 896 KB correct
7 Correct 1 ms 896 KB correct
8 Correct 1 ms 896 KB correct
9 Correct 1 ms 896 KB correct
10 Correct 1 ms 896 KB correct
11 Correct 1 ms 896 KB correct
12 Correct 1 ms 896 KB correct
13 Correct 1 ms 896 KB correct
14 Correct 3 ms 1024 KB correct
15 Correct 2 ms 1152 KB correct
16 Correct 3 ms 1024 KB correct
17 Correct 2 ms 1024 KB correct
18 Correct 1 ms 1024 KB correct
19 Correct 2 ms 1024 KB correct
20 Correct 2 ms 1024 KB correct
21 Correct 2 ms 1024 KB correct
22 Correct 2 ms 1024 KB correct
23 Correct 2 ms 1024 KB correct
24 Correct 2 ms 1024 KB correct
25 Correct 1 ms 896 KB correct
26 Correct 2 ms 1024 KB correct
27 Correct 2 ms 1024 KB correct
28 Correct 1 ms 1024 KB correct
29 Correct 1 ms 896 KB correct
30 Correct 2 ms 1024 KB correct
31 Correct 2 ms 1024 KB correct
32 Correct 2 ms 1024 KB correct
33 Correct 2 ms 1024 KB correct
34 Correct 141 ms 2680 KB correct
35 Correct 138 ms 2432 KB correct
36 Correct 100 ms 2176 KB correct
37 Correct 7 ms 1024 KB correct
38 Correct 142 ms 2560 KB correct
39 Correct 122 ms 2304 KB correct
40 Correct 96 ms 2176 KB correct
41 Correct 153 ms 2432 KB correct
42 Correct 139 ms 2432 KB correct
43 Correct 72 ms 1920 KB correct
44 Correct 56 ms 1664 KB correct
45 Correct 69 ms 1792 KB correct
46 Correct 57 ms 1536 KB correct
47 Correct 25 ms 1280 KB correct
48 Correct 3 ms 1024 KB correct
49 Correct 8 ms 1024 KB correct
50 Correct 24 ms 1280 KB correct
51 Correct 70 ms 1784 KB correct
52 Correct 60 ms 1748 KB correct
53 Correct 52 ms 1536 KB correct
54 Correct 78 ms 1920 KB correct
55 Correct 69 ms 1792 KB correct
56 Correct 71 ms 1792 KB correct
57 Correct 72 ms 1912 KB correct
58 Correct 1 ms 896 KB correct
59 Correct 1 ms 896 KB correct
60 Incorrect 117 ms 4984 KB WA in grader: NO
61 Halted 0 ms 0 KB -