답안 #283749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
283749 2020-08-26T06:50:26 Z erd1 Simurgh (IOI17_simurgh) C++14
51 / 100
150 ms 3712 KB
#include "simurgh.h"

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> pii;
typedef long long lld;
typedef long double ld;

template<typename Iter>
ostream& outIt(ostream& out, Iter b, Iter e){
	for(Iter i = b; i != e; ++i)
		out << (i == b?"":" ") << *i;
	return out;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p){
	return out << '(' << p.ff << ", " << p.ss << ')';
}
template<typename T>
ostream& operator<<(ostream& out, vector<T> v){
	return outIt(out << '[', all(v)) << ']';
}


vector<vector<pii>> G;
vector<bool> asked, ans;
vector<int> te, es, dep, par, pe;
//int c = 0;
int dfs(int i, int d = 1){
	//cout << i << " " << d << " " << par[i] << endl;
	//if(c++>100)exit(-1);
	dep[i] = d;
	int minup = d;
	for(auto x : G[i]){
		if(x.ss == pe[i])continue;
		if(dep[x.ff]){
			//cout << "counter" << x << endl;
			minup = min(minup, dep[x.ff]);
			continue;
		}
		es.pb(x.ss);
		te[x.ss] = es.size();
		pe[x.ff] = x.ss; par[x.ff] = i;
		minup = min(minup, dfs(x.ff, d + 1));
	}
	if(!i)return 0;
	//cout << i << minup << endl;
	if(minup == d){
		ans[pe[i]] = true;
		asked[pe[i]] = true;
	}
	return minup;
}

int asking(int tree, int nontree){
	//cout << "ask " << tree << " " << nontree << endl;
	swap(es[te[tree]-1], nontree);
	int ansx = count_common_roads(es);
	swap(es[te[tree]-1], nontree);
	//cout << ansx << endl;
	return ansx;
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	int m = u.size();
	te.resize(m); asked.resize(m); ans.resize(m); pe.resize(n); par.resize(n); dep.resize(n); pe[0] = -1;
	G.resize(n);
	for(int i = 0; i < m; i++)G[u[i]].pb({v[i], i}), G[v[i]].pb({u[i], i});
	dfs(0);
	int tans = count_common_roads(es);
	//cout << tans << endl;
	//cout << asked << endl;
	//cout << te << es << dep << par << endl;
	for(int i = 0; i < m; i++) if(dep[u[i]] < dep[v[i]])swap(u[i], v[i]);
	for(int i = 0; i < m; i++)
		if(!te[i]){
			//cout << i << endl;
			for(int c = u[i]; c != v[i]; c = par[c]){
				if(asked[pe[c]] && !asked[i]){
					int cans = asking(pe[c], i);
					if(cans == tans)ans[i] = ans[pe[c]];
					else if(cans < tans)ans[i] = false, assert(ans[pe[c]] == true);
					else if(cans > tans)ans[i] = true, assert(ans[pe[c]] == false);
					asked[i] = true;
				}else if(!asked[pe[c]]){
					int cans = asking(pe[c], i);
					if(cans < tans)ans[pe[c]] = true;
					else if(cans > tans)ans[i] = true;
					if(cans != tans) asked[pe[c]] = asked[i] = true;
				}
			}
			//assert(asked[i]);
			for(int c = u[i]; c != v[i]; c = par[c])
				if(!asked[pe[c]])asked[pe[c]] = true, ans[pe[c]] = ans[i];
		}
	//cout << asked << endl << ans << endl;
	vector<int> ret;
	for(int i = 0; i < m; i++){
		//assert(asked[i]);
		if(ans[i])ret.pb(i);
	}
	//assert(ret.size() == n-1);
	return ret;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 0 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 0 ms 256 KB correct
7 Correct 1 ms 256 KB correct
8 Correct 1 ms 256 KB correct
9 Correct 0 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 1 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 0 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 0 ms 256 KB correct
7 Correct 1 ms 256 KB correct
8 Correct 1 ms 256 KB correct
9 Correct 0 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 1 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
14 Correct 2 ms 384 KB correct
15 Correct 2 ms 384 KB correct
16 Correct 3 ms 384 KB correct
17 Correct 2 ms 384 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 2 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 KB correct
22 Correct 1 ms 384 KB correct
23 Correct 0 ms 384 KB correct
24 Correct 1 ms 384 KB correct
25 Correct 1 ms 368 KB correct
26 Correct 1 ms 384 KB correct
27 Correct 2 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 1 ms 384 KB correct
31 Correct 1 ms 384 KB correct
32 Correct 1 ms 384 KB correct
33 Correct 1 ms 384 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 0 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 0 ms 256 KB correct
7 Correct 1 ms 256 KB correct
8 Correct 1 ms 256 KB correct
9 Correct 0 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 1 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
14 Correct 2 ms 384 KB correct
15 Correct 2 ms 384 KB correct
16 Correct 3 ms 384 KB correct
17 Correct 2 ms 384 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 2 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 KB correct
22 Correct 1 ms 384 KB correct
23 Correct 0 ms 384 KB correct
24 Correct 1 ms 384 KB correct
25 Correct 1 ms 368 KB correct
26 Correct 1 ms 384 KB correct
27 Correct 2 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 1 ms 384 KB correct
31 Correct 1 ms 384 KB correct
32 Correct 1 ms 384 KB correct
33 Correct 1 ms 384 KB correct
34 Correct 149 ms 1664 KB correct
35 Correct 146 ms 1784 KB correct
36 Correct 100 ms 1408 KB correct
37 Correct 7 ms 384 KB correct
38 Correct 149 ms 1664 KB correct
39 Correct 130 ms 1664 KB correct
40 Correct 99 ms 1408 KB correct
41 Correct 150 ms 1664 KB correct
42 Correct 145 ms 1664 KB correct
43 Correct 77 ms 1152 KB correct
44 Correct 63 ms 896 KB correct
45 Correct 73 ms 1144 KB correct
46 Correct 58 ms 896 KB correct
47 Correct 25 ms 640 KB correct
48 Correct 2 ms 384 KB correct
49 Correct 7 ms 512 KB correct
50 Correct 23 ms 640 KB correct
51 Correct 72 ms 1024 KB correct
52 Correct 62 ms 896 KB correct
53 Correct 57 ms 896 KB correct
54 Correct 80 ms 1152 KB correct
55 Correct 74 ms 1024 KB correct
56 Correct 75 ms 1024 KB correct
57 Correct 75 ms 1024 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Incorrect 124 ms 3712 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 0 ms 256 KB correct
4 Correct 0 ms 256 KB correct
5 Correct 0 ms 256 KB correct
6 Correct 0 ms 256 KB correct
7 Correct 1 ms 256 KB correct
8 Correct 1 ms 256 KB correct
9 Correct 0 ms 256 KB correct
10 Correct 0 ms 256 KB correct
11 Correct 1 ms 256 KB correct
12 Correct 1 ms 256 KB correct
13 Correct 1 ms 256 KB correct
14 Correct 2 ms 384 KB correct
15 Correct 2 ms 384 KB correct
16 Correct 3 ms 384 KB correct
17 Correct 2 ms 384 KB correct
18 Correct 1 ms 384 KB correct
19 Correct 2 ms 384 KB correct
20 Correct 2 ms 384 KB correct
21 Correct 2 ms 384 KB correct
22 Correct 1 ms 384 KB correct
23 Correct 0 ms 384 KB correct
24 Correct 1 ms 384 KB correct
25 Correct 1 ms 368 KB correct
26 Correct 1 ms 384 KB correct
27 Correct 2 ms 384 KB correct
28 Correct 1 ms 384 KB correct
29 Correct 1 ms 384 KB correct
30 Correct 1 ms 384 KB correct
31 Correct 1 ms 384 KB correct
32 Correct 1 ms 384 KB correct
33 Correct 1 ms 384 KB correct
34 Correct 149 ms 1664 KB correct
35 Correct 146 ms 1784 KB correct
36 Correct 100 ms 1408 KB correct
37 Correct 7 ms 384 KB correct
38 Correct 149 ms 1664 KB correct
39 Correct 130 ms 1664 KB correct
40 Correct 99 ms 1408 KB correct
41 Correct 150 ms 1664 KB correct
42 Correct 145 ms 1664 KB correct
43 Correct 77 ms 1152 KB correct
44 Correct 63 ms 896 KB correct
45 Correct 73 ms 1144 KB correct
46 Correct 58 ms 896 KB correct
47 Correct 25 ms 640 KB correct
48 Correct 2 ms 384 KB correct
49 Correct 7 ms 512 KB correct
50 Correct 23 ms 640 KB correct
51 Correct 72 ms 1024 KB correct
52 Correct 62 ms 896 KB correct
53 Correct 57 ms 896 KB correct
54 Correct 80 ms 1152 KB correct
55 Correct 74 ms 1024 KB correct
56 Correct 75 ms 1024 KB correct
57 Correct 75 ms 1024 KB correct
58 Correct 0 ms 256 KB correct
59 Correct 0 ms 256 KB correct
60 Incorrect 124 ms 3712 KB WA in grader: NO
61 Halted 0 ms 0 KB -