Submission #248830

# Submission time Handle Problem Language Result Execution time Memory
248830 2020-07-13T14:14:48 Z kostia244 Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 384 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 505;
int n, m;
vector<array<int, 2>> g[maxn], tr[maxn];
vector<int> state, te, vis, used;
void pre(int v) {
	vis[v] = 1;
	for(auto [i, id] : g[v]) if(!vis[i]) {
		pre(i);
		used.push_back(id);
		te[id] = 1;
		tr[v].push_back({i, id});
		tr[i].push_back({v, id});
	}
}
vector<int> _path;
bool find(int v, int t) {
	if(v == t) return true;
	vis[v] = 1;
	for(auto [i, id] : tr[v]) if(!vis[i]) {
		if(find(i, t)) _path.push_back(id);
	}
}
vector<int> find_path(int u, int v) {
	_path.clear();
	vis.assign(n, 0);
	find(u, v);
	return _path;
}
int alter(int id, int nid) {
	vector<int> t = used;
	for(auto &i : t) if(i == id) swap(i, t.back());
	t.pop_back();
	t.push_back(nid);
	return count_common_roads(t);
}
std::vector<int> find_roads(int _n, std::vector<int> u, std::vector<int> v) {
	for(int i = 0; i < u.size(); i++) g[u[i]].push_back({v[i], i});
	for(int i = 0; i < u.size(); i++) g[v[i]].push_back({u[i], i});
	n = _n;
	m = u.size();
	state.resize(m);
	te.resize(m);
	vis.resize(n);
	pre(0);
	int init = count_common_roads(used);
	for(int i = 0; i < m; i++) if(!te[i]) {
		vector<int> t = find_path(u[i], v[i]);
		
		int det = 0;
		for(auto id : t) {
			if(state[id]) {
				int tmp = alter(id, i);
				if(state[id] == 2) det = 1+(tmp == init);
				else det = 1+(tmp>init);
				break;
			}
		}
		if(det) {
			state[i] = det;
			for(auto &id : t) if(!state[id]) {
				int tmp = alter(id, i);
				if(det == 2) det = 1+(tmp == init);
				else det = 1+(tmp>init);
			}
			continue;
		}
		vector<int> results;
		int mn = init;
		for(auto id : t) {
			results.push_back(alter(id, i));
			mn = min(mn, results.back());
		}
		for(int i = 0; i < t.size(); i++)
			state[t[i]] = 1+(results[i]==mn);
		state[i] = 1+(init==mn);
	}
	
	std::vector<int> r;
	for(int i = 0; i < m; i++) if(state[i] != 1) r.push_back(i);
	return r;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:40:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < u.size(); i++) g[u[i]].push_back({v[i], i});
                 ~~^~~~~~~~~~
simurgh.cpp:41:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < u.size(); i++) g[v[i]].push_back({u[i], i});
                 ~~^~~~~~~~~~
simurgh.cpp:76:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < t.size(); i++)
                  ~~^~~~~~~~~~
simurgh.cpp: In function 'bool find(int, int)':
simurgh.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB correct
2 Incorrect 1 ms 384 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB WA in grader: NO
2 Halted 0 ms 0 KB -