Submission #590550

# Submission time Handle Problem Language Result Execution time Memory
590550 2022-07-06T06:16:42 Z 장태환(#8413) Amusement Park (JOI17_amusement_park) C++14
0 / 100
107 ms 126576 KB
#include "Joi.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
	int uf[10100];
	int f(int n)
	{
		return uf[n] == n ? n : uf[n] = f(uf[n]);
	}
	void u(int n, int m)
	{
		uf[f(n)] = f(m);
	}
	vector<int>link[10100];
	vector<int>tt[10100];
	bool cnt[10100][10100];
	int bass[100100];
	void dfs(int n, int p)
	{
		int i;
		for (i = 0; i < tt[n].size(); i++)
		{
			if (tt[n][i] == n)
				continue;
			int j;
			int r = 0;
			for (j = 0; j < tt[n].size(); j++)
			{
				if (i == j)
					continue;
				if (cnt[tt[n][i]][tt[n][j]])
				{
					r++;
				}
			}
			if (r == 1)
				break;
		}
		int ers = tt[n][i];
		for (i = 0; i < link[n].size(); i++)
		{
			if (link[n][i] == p)
				continue;
			int j;
			if (tt[link[n][i]].size())
				goto T;
			for (j = 0; j < tt[n].size(); j++)
			{
				if (tt[n][j] != ers)
				{
					tt[link[n][i]].push_back(tt[n][j]);
				}
			}
			bass[link[n][i]] = ers;
			tt[link[n][i]].push_back(link[n][i]);
		T:
			dfs(link[n][i], n);
		}
	}
	vector<int>fs;
	void dfs2(int n, int p)
	{
		if (fs.size() == 60)
		{
			return;
		}
		int i;
		bass[n] = fs.size();
		fs.push_back(n);
		for (i = 0; i < link[n].size(); i++)
		{
			if (link[n][i] == p)
				continue;
			dfs2(link[n][i], n);
		}
	}
}

void Joi(int N, int M, int A[], int B[], long long X, int T) 
{
	memset(bass, -1, sizeof(bass));
	int i;
	for (i = 0; i < N; i++)
	{
		uf[i] = i;
	}
	for (i = 0; i < M; i++)
	{
		if (f(A[i]) != f(B[i]))
		{
			u(A[i], B[i]);
			cnt[A[i]][B[i]] = true;
			cnt[B[i]][A[i]] = true;
			link[A[i]].push_back(B[i]);
			link[B[i]].push_back(A[i]);
		}
	}
	dfs2(0, -1);
	for (i = 0; i < fs.size(); i++)
	{
		tt[fs[i]] = fs;
	}
	dfs(0, -1);
	for (i = 0; i < N; i++)
	{
		MessageBoard(i, (int)((X >> (bass[i]))&1));
	}
}
#include "Ioi.h"
#include <bits/stdc++.h>
using namespace std;
namespace
{
	int uf[10100];
	int f(int n)
	{
		return uf[n] == n ? n : uf[n] = f(uf[n]);
	}
	void u(int n, int m)
	{
		uf[f(n)] = f(m);
	}
	vector<int>link[10100];
	vector<int>tt[10100];
	bool cnt[10100][10100];
	int bass[100100];
	void dfs(int n, int p)
	{
		int i;
		for (i = 0; i < tt[n].size(); i++)
		{
			if (tt[n][i] == n)
				continue;
			int j;
			int r = 0;
			for (j = 0; j < tt[n].size(); j++)
			{
				if (i == j)
					continue;
				if (cnt[tt[n][i]][tt[n][j]])
				{
					r++;
				}
			}
			if (r == 1)
				break;
		}
		int ers = tt[n][i];
		for (i = 0; i < link[n].size(); i++)
		{
			if (link[n][i] == p)
				continue;
			int j;
			if (tt[link[n][i]].size())
				goto T;
			for (j = 0; j < tt[n].size(); j++)
			{
				if (tt[n][j] != ers)
				{
					tt[link[n][i]].push_back(tt[n][j]);
				}
			}
			bass[link[n][i]] = ers;
			tt[link[n][i]].push_back(link[n][i]);
		T:
			dfs(link[n][i], n);
		}
	}
	vector<int>fs;
	void dfs2(int n, int p)
	{
		if (fs.size() == 60)
		{
			return;
		}
		int i;
		bass[n] = fs.size();
		fs.push_back(n);
		for (i = 0; i < link[n].size(); i++)
		{
			if (link[n][i] == p)
				continue;
			dfs2(link[n][i], n);
		}
	}
	int ans[60];
	bool ind[20010];
	void dfs3(int n, int p)
	{
		int i;
		for (i = 0; i < link[n].size(); i++)
		{
			if (link[n][i] == p)
				continue;
			if (!ind[link[n][i]])
				continue;
			ans[bass[link[n][i]]] = Move(link[n][i]);
			dfs3(link[n][i], n);
			Move(n);
		}
	}
}

long long Ioi(int N, int M, int A[], int B[], int P, int V, int T) {
	memset(bass, -1, sizeof(bass));
	int i;
	for (i = 0; i < N; i++)
	{
		uf[i] = i;
	}
	for (i = 0; i < M; i++)
	{
		if (f(A[i]) != f(B[i]))
		{
			u(A[i], B[i]);
			cnt[A[i]][B[i]] = true;
			cnt[B[i]][A[i]] = true;
			link[A[i]].push_back(B[i]);
			link[B[i]].push_back(A[i]);
		}
	}
	dfs2(0, -1);
	for (i = 0; i < fs.size(); i++)
	{
		tt[fs[i]] = fs;
	}
	dfs(0, -1);
	ans[bass[P]] = V;
	for (i = 0; i < tt[P].size(); i++)
	{
		ind[tt[P][i]] = 1;
	}
	dfs3(P, -1);
	long long rans = 0;
	for (i = 0; i < 60; i++)
	{
		rans += (1LL << i) * ans[i];
	}
	return rans;
}

Compilation message

Joi.cpp: In function 'void {anonymous}::dfs(int, int)':
Joi.cpp:21:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for (i = 0; i < tt[n].size(); i++)
      |               ~~^~~~~~~~~~~~~~
Joi.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |    for (j = 0; j < tt[n].size(); j++)
      |                ~~^~~~~~~~~~~~~~
Joi.cpp:40:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for (i = 0; i < link[n].size(); i++)
      |               ~~^~~~~~~~~~~~~~~~
Joi.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |    for (j = 0; j < tt[n].size(); j++)
      |                ~~^~~~~~~~~~~~~~
Joi.cpp: In function 'void {anonymous}::dfs2(int, int)':
Joi.cpp:70:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   for (i = 0; i < link[n].size(); i++)
      |               ~~^~~~~~~~~~~~~~~~
Joi.cpp: In function 'void Joi(int, int, int*, int*, long long int, int)':
Joi.cpp:99:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |  for (i = 0; i < fs.size(); i++)
      |              ~~^~~~~~~~~~~

Ioi.cpp: In function 'void {anonymous}::dfs(int, int)':
Ioi.cpp:22:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   for (i = 0; i < tt[n].size(); i++)
      |               ~~^~~~~~~~~~~~~~
Ioi.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |    for (j = 0; j < tt[n].size(); j++)
      |                ~~^~~~~~~~~~~~~~
Ioi.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for (i = 0; i < link[n].size(); i++)
      |               ~~^~~~~~~~~~~~~~~~
Ioi.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    for (j = 0; j < tt[n].size(); j++)
      |                ~~^~~~~~~~~~~~~~
Ioi.cpp: In function 'void {anonymous}::dfs2(int, int)':
Ioi.cpp:71:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for (i = 0; i < link[n].size(); i++)
      |               ~~^~~~~~~~~~~~~~~~
Ioi.cpp: In function 'void {anonymous}::dfs3(int, int)':
Ioi.cpp:83:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for (i = 0; i < link[n].size(); i++)
      |               ~~^~~~~~~~~~~~~~~~
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:115:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |  for (i = 0; i < fs.size(); i++)
      |              ~~^~~~~~~~~~~
Ioi.cpp:121:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |  for (i = 0; i < tt[P].size(); i++)
      |              ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3084 KB Output is correct
2 Correct 2 ms 3600 KB Output is correct
3 Incorrect 3 ms 5140 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 107 ms 126576 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3088 KB Output is correct
2 Correct 2 ms 3344 KB Output is correct
3 Correct 2 ms 3332 KB Output is correct
4 Correct 10 ms 16712 KB Output is correct
5 Incorrect 9 ms 16704 KB Wrong Answer [7]
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 126368 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 126368 KB Wrong Answer [7]
2 Halted 0 ms 0 KB -