답안 #340908

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340908 2020-12-28T13:41:05 Z pggp Simurgh (IOI17_simurgh) C++14
0 / 100
2 ms 1920 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){
	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 < n; ++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:23:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  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:64:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for(int i = 0; i < v_back.size(); i++){
      |                 ~~^~~~~~~~~~~~~~~
simurgh.cpp:106:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |   for (int j = 0; j < an.size(); ++j)
      |                   ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1920 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1920 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1920 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 1772 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1920 KB WA in grader: NO
2 Halted 0 ms 0 KB -