Submission #283747

# Submission time Handle Problem Language Result Execution time Memory
283747 2020-08-26T06:49:42 Z erd1 Simurgh (IOI17_simurgh) C++14
0 / 100
37 ms 8032 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 1 ms 256 KB correct
4 Correct 0 ms 256 KB correct
5 Correct 1 ms 256 KB correct
6 Runtime error 1 ms 512 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 1 ms 256 KB correct
4 Correct 0 ms 256 KB correct
5 Correct 1 ms 256 KB correct
6 Runtime error 1 ms 512 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 1 ms 256 KB correct
4 Correct 0 ms 256 KB correct
5 Correct 1 ms 256 KB correct
6 Runtime error 1 ms 512 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Runtime error 37 ms 8032 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB correct
2 Correct 0 ms 256 KB correct
3 Correct 1 ms 256 KB correct
4 Correct 0 ms 256 KB correct
5 Correct 1 ms 256 KB correct
6 Runtime error 1 ms 512 KB Execution killed with signal 11
7 Halted 0 ms 0 KB -