답안 #300956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
300956 2020-09-17T15:29:00 Z pacha2880 Simurgh (IOI17_simurgh) C++17
30 / 100
248 ms 4872 KB
#include <bits/stdc++.h>
#include "simurgh.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define md(a, b)		((a) % b + b) % b
#define mod(a)			md(a, MOD)
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define forn(i, n)			for(int i = 0; i < n; i++)
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
//int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef long long 		ll;
typedef long double ld;	
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 550;
const int MOD = 1000000007;
const int MOD1 = 998244353;
const double EPS = 1e-9;
const double PI = acos(-1); 
vector<pair<int, int>> g[tam];
vector<pair<int, int>> ng[tam];
vector<int> r;
int parent[tam * tam];
int color[tam * tam];
bool visited[tam], used[tam * tam], vasited[tam * tam];
int poso[tam * tam];
int con = 0;
int n, m;
void dfs0(int node)
{
	visited[node] = 1;
	fore(i, 0, g[node].size())
	{
		if(!visited[g[node][i].f])
		{
			r.pb(g[node][i].s);
			used[g[node][i].s] = 1;
			poso[g[node][i].s] = r.size() - 1;
			ng[node].pb(g[node][i]);
			ng[g[node][i].f].pb({node, g[node][i].s});
			dfs0(g[node][i].f);
		}
	}
}
int find(int n)
{
	if(parent[n] == -1) return n;
	return parent[n] = find(parent[n]);
}
vector<int> res;
bool cicl(int node, int par)
{
	visited[node] = 1;
	//cout<<node<<'\n';
	for(auto cat : ng[node])
	{
		if(!visited[cat.f])
		{
			if(cicl(cat.f, node))
			{
				//cout<<"++++++  "<<node<<' '<<cat.f<<' '<<cat.s<<'\n';
				res.pb(cat.s);
				return true;
			}
		}
		else if(cat.f != par)
		{
			//cout<<"======  "<<node<<' '<<cat.f<<' '<<cat.s<<'\n';
			res.pb(cat.s);
			return true;
		}
	}
	return false;
}
vector<int> find_roads(int nn, vector<int> u, vector<int> v) {
	n = nn;
	m = u.size();
	fore(i, 0, m)
	{
		g[u[i]].pb({v[i], i});
		g[v[i]].pb({u[i], i});
	}
	dfs0(0);
	int x = count_common_roads(r), y, a, b;
	if(x == n - 1) return r;
	//cout<<r.size()<<' '<<x<<'\n';
	/*fore(i, 0, r.size())
	{
		cout<<r[i]<<','<<poso[r[i]]<<"  ";
	}
	cout<<'\n';*/
	int remp;
	int cont, sel;
	mem(parent, -1);
	bool bon;
	fore(i, 0, m)
	{
		if(!used[i])
		{
			//cout<<i<<' '<<v[i]<<' '<<u[i]<<'\n';
			ng[u[i]].pb({v[i], i});
			ng[v[i]].pb({u[i], i});
			fore(i, 0, n) visited[i] = 0;
			res.clear();
			cicl(u[i], -1);
			ng[u[i]].pop_back();
			ng[v[i]].pop_back();
			vasited[i] = 1;
			cont = 0;
			//cout<<res.size()<<'\n';
			//cout<<"mi ciclo  "<<res[0]<<'\n';
			bon = false;
			fore(j, 1, res.size())
			{
				//cout<<res[j]<<','<<poso[res[j]]<<','<<r[poso[res[j]]]<<' ';
				remp = res[j];
				if(vasited[remp])
					sel = remp;
				else
				{
					r[poso[remp]] = i;
					y = count_common_roads(r);
					if(y == x)
					{
						cont++;
						a = find(i);
						b = find(remp);
						if(a != b)
						{
							if(color[a] == 0)
								color[a] = color[b];
							parent[a] = b;
						}
					}
					else if(y == x + 1)
					{
						bon = true;
						color[find(i)] = 1;
						color[find(remp)] = -1;
					}
					else
					{
						bon = true;
						color[find(i)] = -1;
						color[find(remp)] = 1;
					}
					r[poso[remp]] = remp;
				}
				vasited[remp] = 1;
			}
			//cout<<"\n\n";
			if(cont == res.size() - 1)
				color[find(i)] = -1;
			else if(!bon)
			{
				remp = sel;
				r[poso[remp]] = i;
				y = count_common_roads(r);
				if(y == x)
				{
					a = find(i);
					b = find(remp);
					if(a != b)
					{
						if(color[a] == 0)
							color[a] = color[b];
						parent[a] = b;
					}
				}
				else if(y == x + 1)
				{
					bon = true;
					color[find(i)] = 1;
					color[find(remp)] = -1;
				}
				else
				{
					bon = true;
					color[find(i)] = -1;
					color[find(remp)] = 1;
				}
				r[poso[remp]] = remp;
			}
		}
	}
	//cout<<"hola\n";
	r.clear();
	fore(i, 0, m)
	{
		color[i] = color[find(i)];
		//cout<<u[i]<<'-'<<v[i]<<' '<<i<<" color -> "<<color[i]<<'\n';
		if(color[i] >= 0)
		{
			color[i] = 1;
			//cout<<i<<'\n';
			r.pb(i);
		}
		//cout<<u[i]<<'-'<<v[i]<<' '<<i<<" color -> "<<color[i]<<'\n';
	}
	//cout<<"cocacola\n";
	return r;
}

Compilation message

simurgh.cpp: In function 'void dfs0(int)':
simurgh.cpp:16:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 | #define fore(i, b, e) for(int i = b; i < e; i++)
......
   49 |  fore(i, 0, g[node].size())
      |       ~~~~~~~~~~~~~~~~~~~~              
simurgh.cpp:49:2: note: in expansion of macro 'fore'
   49 |  fore(i, 0, g[node].size())
      |  ^~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:16:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 | #define fore(i, b, e) for(int i = b; i < e; i++)
......
  130 |    fore(j, 1, res.size())
      |         ~~~~~~~~~~~~~~~~                
simurgh.cpp:130:4: note: in expansion of macro 'fore'
  130 |    fore(j, 1, res.size())
      |    ^~~~
simurgh.cpp:169:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  169 |    if(cont == res.size() - 1)
      |       ~~~~~^~~~~~~~~~~~~~~~~
simurgh.cpp:64:13: warning: 'sel' may be used uninitialized in this function [-Wmaybe-uninitialized]
   64 |  if(parent[n] == -1) return n;
      |     ~~~~~~~~^
simurgh.cpp:110:12: note: 'sel' was declared here
  110 |  int cont, sel;
      |            ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1536 KB correct
2 Correct 1 ms 1536 KB correct
3 Correct 1 ms 1536 KB correct
4 Correct 1 ms 1536 KB correct
5 Correct 2 ms 1536 KB correct
6 Correct 2 ms 1536 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 1536 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 1536 KB correct
13 Correct 1 ms 1536 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1536 KB correct
2 Correct 1 ms 1536 KB correct
3 Correct 1 ms 1536 KB correct
4 Correct 1 ms 1536 KB correct
5 Correct 2 ms 1536 KB correct
6 Correct 2 ms 1536 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 1536 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 1536 KB correct
13 Correct 1 ms 1536 KB correct
14 Correct 6 ms 1536 KB correct
15 Correct 4 ms 1536 KB correct
16 Correct 4 ms 1536 KB correct
17 Correct 4 ms 1536 KB correct
18 Correct 2 ms 1536 KB correct
19 Correct 3 ms 1536 KB correct
20 Correct 4 ms 1536 KB correct
21 Correct 3 ms 1536 KB correct
22 Correct 3 ms 1536 KB correct
23 Correct 2 ms 1536 KB correct
24 Correct 2 ms 1536 KB correct
25 Correct 2 ms 1512 KB correct
26 Correct 3 ms 1536 KB correct
27 Correct 3 ms 1536 KB correct
28 Correct 2 ms 1536 KB correct
29 Correct 1 ms 1536 KB correct
30 Correct 2 ms 1536 KB correct
31 Correct 2 ms 1536 KB correct
32 Correct 3 ms 1536 KB correct
33 Correct 2 ms 1536 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1536 KB correct
2 Correct 1 ms 1536 KB correct
3 Correct 1 ms 1536 KB correct
4 Correct 1 ms 1536 KB correct
5 Correct 2 ms 1536 KB correct
6 Correct 2 ms 1536 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 1536 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 1536 KB correct
13 Correct 1 ms 1536 KB correct
14 Correct 6 ms 1536 KB correct
15 Correct 4 ms 1536 KB correct
16 Correct 4 ms 1536 KB correct
17 Correct 4 ms 1536 KB correct
18 Correct 2 ms 1536 KB correct
19 Correct 3 ms 1536 KB correct
20 Correct 4 ms 1536 KB correct
21 Correct 3 ms 1536 KB correct
22 Correct 3 ms 1536 KB correct
23 Correct 2 ms 1536 KB correct
24 Correct 2 ms 1536 KB correct
25 Correct 2 ms 1512 KB correct
26 Correct 3 ms 1536 KB correct
27 Correct 3 ms 1536 KB correct
28 Correct 2 ms 1536 KB correct
29 Correct 1 ms 1536 KB correct
30 Correct 2 ms 1536 KB correct
31 Correct 2 ms 1536 KB correct
32 Correct 3 ms 1536 KB correct
33 Correct 2 ms 1536 KB correct
34 Correct 248 ms 2680 KB correct
35 Correct 247 ms 2808 KB correct
36 Correct 168 ms 2548 KB correct
37 Incorrect 11 ms 1568 KB WA in grader: NO
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 1536 KB correct
3 Incorrect 199 ms 4872 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1536 KB correct
2 Correct 1 ms 1536 KB correct
3 Correct 1 ms 1536 KB correct
4 Correct 1 ms 1536 KB correct
5 Correct 2 ms 1536 KB correct
6 Correct 2 ms 1536 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 1 ms 384 KB correct
9 Correct 0 ms 384 KB correct
10 Correct 1 ms 1536 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 1536 KB correct
13 Correct 1 ms 1536 KB correct
14 Correct 6 ms 1536 KB correct
15 Correct 4 ms 1536 KB correct
16 Correct 4 ms 1536 KB correct
17 Correct 4 ms 1536 KB correct
18 Correct 2 ms 1536 KB correct
19 Correct 3 ms 1536 KB correct
20 Correct 4 ms 1536 KB correct
21 Correct 3 ms 1536 KB correct
22 Correct 3 ms 1536 KB correct
23 Correct 2 ms 1536 KB correct
24 Correct 2 ms 1536 KB correct
25 Correct 2 ms 1512 KB correct
26 Correct 3 ms 1536 KB correct
27 Correct 3 ms 1536 KB correct
28 Correct 2 ms 1536 KB correct
29 Correct 1 ms 1536 KB correct
30 Correct 2 ms 1536 KB correct
31 Correct 2 ms 1536 KB correct
32 Correct 3 ms 1536 KB correct
33 Correct 2 ms 1536 KB correct
34 Correct 248 ms 2680 KB correct
35 Correct 247 ms 2808 KB correct
36 Correct 168 ms 2548 KB correct
37 Incorrect 11 ms 1568 KB WA in grader: NO
38 Halted 0 ms 0 KB -