답안 #839635

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839635 2023-08-30T11:01:24 Z parsadox2 Stranded Far From Home (BOI22_island) C++17
0 / 100
119 ms 35052 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;
int n , s[N] , m , pos[N] , dis[N] , par[N];
vector <int> adj[N];

bool cmp(int a , int b)
{
	return s[a] < s[b];
}

int root(int v)
{
	if(par[v] < 0)
		return v;
	int R = root(par[v]);
	dis[v] |= dis[par[v]];
	par[v] = R;
	return R;
}

void Add(int v)
{
	vector <int> vec;
	for(auto u : adj[v])  if(pos[u] < pos[v])
		vec.push_back(root(u));
	sort(vec.begin() , vec.end());
	vec.resize(unique(vec.begin() , vec.end()) - vec.begin());
	for(auto u : vec)
	{
		if(par[u] > par[v])
			dis[u] = 1;
		par[v] += par[u];
		par[u] = v;
	}
}

void solve()
{
	cin >> n >> m;
	vector <int> vec;
	for(int i = 1 ; i <= n ; i++)
	{
		cin >> s[i];
		vec.push_back(i);
	}
	for(int i = 0 ; i < m ; i++)
	{
		int v , u;  cin >> v >> u;
		adj[v].push_back(u);
		adj[u].push_back(v);
	}
	sort(vec.begin() , vec.end() , cmp);
	for(int i = 0 ; i < n ; i++)
		pos[vec[i]] = i;
	for(int i = 1 ; i <= n ; i++)
		par[i] = -s[i];
	for(auto u : vec)
		Add(u);
	for(int i = 1 ; i <= n ; i++)
	{
		int tmp = root(i);
		cout << (dis[i] ^ 1);
	}
	cout << endl;
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);  cout.tie(0);
	int Tc;
	Tc = 1;
	while(Tc--)
		solve();
	return 0;
}

Compilation message

island.cpp: In function 'void solve()':
island.cpp:64:7: warning: unused variable 'tmp' [-Wunused-variable]
   64 |   int tmp = root(i);
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Runtime error 7 ms 10156 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5032 KB Output is correct
2 Correct 3 ms 4964 KB Output is correct
3 Runtime error 97 ms 33448 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Runtime error 119 ms 34916 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Runtime error 107 ms 35052 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 5028 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Runtime error 7 ms 10156 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -