Submission #340909

# Submission time Handle Problem Language Result Execution time Memory
340909 2020-12-28T13:49:28 Z pggp Simurgh (IOI17_simurgh) C++14
13 / 100
128 ms 6636 KB
#include <bits/stdc++.h>
#include "simurgh.h"

using namespace std;


int k[30000];

vector < int > E[30000];
vector < int > E_id[30000];
bool used[30000];
int parent[30000];
int parent_road[30000];
int depth[30000];

vector < int > u_back, v_back;
vector < int > id;

vector < int > tree;

void dfs(int vertex){
	//outcout << vertex << endl;
	used[vertex] = true;
	for(int i = 0; i < E[vertex].size(); i++){
		int v = E[vertex][i];
		if(!used[v]){
			parent[v] = vertex;
			parent_road[v] = E_id[vertex][i];
			tree.push_back(parent_road[v]);

			//cout << vertex << " to " << v << endl;
			depth[v] = depth[vertex] + 1;
			dfs(v);
		}
		else if (v != parent[vertex] and depth[v] < depth[vertex]){
			v_back.push_back(vertex);
			u_back.push_back(v);
			id.push_back(E_id[vertex][i]);
		}
	}
}


vector < int > find_roads(int n, vector < int > u, vector < int > v){

	for (int i = 0; i < n; ++i)
	{
		k[i] = -1;
	}

	int m = u.size();
	for (int i = 0; i < m; ++i)
	{
		E[u[i]].push_back(v[i]);
		E_id[u[i]].push_back(i);
		E[v[i]].push_back(u[i]);
		E_id[v[i]].push_back(i);
	}
	parent[0] = -1;
	dfs(0);

	int tr = count_common_roads(tree);

	// tutaj zaczyna się zabawa z cyklami
	for(int i = 0; i < v_back.size(); i++){
		vector < int > cycle;
		cycle.push_back(id[i]);
		int cur = v_back[i];
		//cout << v_back[i] << " " << u_back[i] << endl;
		while(cur != u_back[i]){
			cycle.push_back(parent_road[cur]);
			cur = parent[cur];
		}
		vector < int > an;

		int minim = 100000;
		int maxim = 0;

		for(int t : cycle){
			if(t == id[i]){
				an.push_back(tr);
				minim = min(minim, tr);
				maxim = max(maxim, tr);
				continue;
			}
			//cout << "t = " << t << endl;
			vector < int > to_q;
			// drzewo z cyklem bez t
			for(int e : tree){
				if(e != t){
					to_q.push_back(e);
				}
			}
			to_q.push_back(id[i]);
			int resp = count_common_roads(to_q);
			an.push_back(resp);
			minim = min(minim, resp);
			maxim = max(maxim, resp);
		}

		if(maxim == minim){
			for(int e :cycle){
				k[e] = 0;
			}
		}

		for (int j = 0; j < an.size(); ++j)
		{
			if(an[j] == maxim){
				k[cycle[j]] = 0;
			}
			else{
				k[cycle[j]] = 1;
			}
		}


//		cout << endl;
	}


	vector < int > ans;
	for (int i = 0; i < m; ++i)
	{
		if(k[i] == 1 or k[i] == -1){
			ans.push_back(i);
		}
	}
	return ans;
}

Compilation message

simurgh.cpp: In function 'void dfs(int)':
simurgh.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for(int i = 0; i < E[vertex].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i = 0; i < v_back.size(); i++){
      |                 ~~^~~~~~~~~~~~~~~
simurgh.cpp:107:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |   for (int j = 0; j < an.size(); ++j)
      |                   ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1772 KB correct
2 Correct 1 ms 1772 KB correct
3 Correct 2 ms 1772 KB correct
4 Correct 1 ms 1772 KB correct
5 Correct 1 ms 1772 KB correct
6 Correct 1 ms 1772 KB correct
7 Correct 2 ms 1772 KB correct
8 Correct 1 ms 1772 KB correct
9 Correct 1 ms 1772 KB correct
10 Correct 2 ms 1792 KB correct
11 Correct 1 ms 1772 KB correct
12 Correct 2 ms 1772 KB correct
13 Correct 1 ms 1772 KB correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1772 KB correct
2 Correct 1 ms 1772 KB correct
3 Correct 2 ms 1772 KB correct
4 Correct 1 ms 1772 KB correct
5 Correct 1 ms 1772 KB correct
6 Correct 1 ms 1772 KB correct
7 Correct 2 ms 1772 KB correct
8 Correct 1 ms 1772 KB correct
9 Correct 1 ms 1772 KB correct
10 Correct 2 ms 1792 KB correct
11 Correct 1 ms 1772 KB correct
12 Correct 2 ms 1772 KB correct
13 Correct 1 ms 1772 KB correct
14 Correct 28 ms 1900 KB correct
15 Correct 30 ms 1900 KB correct
16 Correct 28 ms 1900 KB correct
17 Correct 22 ms 1772 KB correct
18 Correct 9 ms 1792 KB correct
19 Correct 23 ms 1772 KB correct
20 Correct 22 ms 1772 KB correct
21 Correct 21 ms 1772 KB correct
22 Incorrect 12 ms 1772 KB WA in grader: NO
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1772 KB correct
2 Correct 1 ms 1772 KB correct
3 Correct 2 ms 1772 KB correct
4 Correct 1 ms 1772 KB correct
5 Correct 1 ms 1772 KB correct
6 Correct 1 ms 1772 KB correct
7 Correct 2 ms 1772 KB correct
8 Correct 1 ms 1772 KB correct
9 Correct 1 ms 1772 KB correct
10 Correct 2 ms 1792 KB correct
11 Correct 1 ms 1772 KB correct
12 Correct 2 ms 1772 KB correct
13 Correct 1 ms 1772 KB correct
14 Correct 28 ms 1900 KB correct
15 Correct 30 ms 1900 KB correct
16 Correct 28 ms 1900 KB correct
17 Correct 22 ms 1772 KB correct
18 Correct 9 ms 1792 KB correct
19 Correct 23 ms 1772 KB correct
20 Correct 22 ms 1772 KB correct
21 Correct 21 ms 1772 KB correct
22 Incorrect 12 ms 1772 KB WA in grader: NO
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1772 KB correct
2 Correct 2 ms 1792 KB correct
3 Incorrect 128 ms 6636 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1772 KB correct
2 Correct 1 ms 1772 KB correct
3 Correct 2 ms 1772 KB correct
4 Correct 1 ms 1772 KB correct
5 Correct 1 ms 1772 KB correct
6 Correct 1 ms 1772 KB correct
7 Correct 2 ms 1772 KB correct
8 Correct 1 ms 1772 KB correct
9 Correct 1 ms 1772 KB correct
10 Correct 2 ms 1792 KB correct
11 Correct 1 ms 1772 KB correct
12 Correct 2 ms 1772 KB correct
13 Correct 1 ms 1772 KB correct
14 Correct 28 ms 1900 KB correct
15 Correct 30 ms 1900 KB correct
16 Correct 28 ms 1900 KB correct
17 Correct 22 ms 1772 KB correct
18 Correct 9 ms 1792 KB correct
19 Correct 23 ms 1772 KB correct
20 Correct 22 ms 1772 KB correct
21 Correct 21 ms 1772 KB correct
22 Incorrect 12 ms 1772 KB WA in grader: NO
23 Halted 0 ms 0 KB -