Submission #839676

# Submission time Handle Problem Language Result Execution time Memory
839676 2023-08-30T12:16:34 Z parsadox2 Stranded Far From Home (BOI22_island) C++14
100 / 100
161 ms 28064 KB
#include <bits/stdc++.h>
#define int long long
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));
	int tmp = 0;
	for(auto u : vec)
	{
		if(par[u] >= 0)
			continue;
		//cout << v << " : " << u << " " << par[u] << endl;
		if(abs(par[u]) < s[v])
		{
			dis[u] = 1;
			//cout << v << " : " << u << endl;
		}
		par[v] += par[u];
		par[u] = v;
	}
	//cout << v << " = " << par[v] << endl;
}

void solve()
{
	cin >> n >> m;
	vector <int> vec;
	int sum = 0;
	for(int i = 1 ; i <= n ; i++)
	{
		cin >> s[i];
		sum -= 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];
		dis[i] = 0;
	}
	for(auto u : vec)
		Add(u);
	for(int i = 1 ; i <= n ; i++)
	{
		int tmp = root(i);
		cout << ((dis[i] == 0 && par[tmp] == sum) ? 1 : 0);
	}
	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 Add(long long int)':
island.cpp:29:6: warning: unused variable 'tmp' [-Wunused-variable]
   29 |  int tmp = 0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5172 KB Output is correct
6 Correct 3 ms 5168 KB Output is correct
7 Correct 3 ms 5176 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5236 KB Output is correct
10 Correct 3 ms 5172 KB Output is correct
11 Correct 3 ms 5204 KB Output is correct
12 Correct 4 ms 5204 KB Output is correct
13 Correct 3 ms 5164 KB Output is correct
14 Correct 3 ms 5196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 113 ms 20244 KB Output is correct
4 Correct 105 ms 23384 KB Output is correct
5 Correct 105 ms 24020 KB Output is correct
6 Correct 115 ms 24648 KB Output is correct
7 Correct 110 ms 24640 KB Output is correct
8 Correct 129 ms 24768 KB Output is correct
9 Correct 121 ms 25992 KB Output is correct
10 Correct 79 ms 27328 KB Output is correct
11 Correct 81 ms 27076 KB Output is correct
12 Correct 108 ms 23256 KB Output is correct
13 Correct 113 ms 22156 KB Output is correct
14 Correct 100 ms 22432 KB Output is correct
15 Correct 93 ms 23728 KB Output is correct
16 Correct 82 ms 22896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 136 ms 19176 KB Output is correct
3 Correct 161 ms 23840 KB Output is correct
4 Correct 107 ms 23744 KB Output is correct
5 Correct 99 ms 22168 KB Output is correct
6 Correct 140 ms 23668 KB Output is correct
7 Correct 123 ms 23740 KB Output is correct
8 Correct 144 ms 23668 KB Output is correct
9 Correct 76 ms 22804 KB Output is correct
10 Correct 97 ms 23100 KB Output is correct
11 Correct 111 ms 22260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 147 ms 20284 KB Output is correct
3 Correct 142 ms 24612 KB Output is correct
4 Correct 144 ms 24744 KB Output is correct
5 Correct 130 ms 24760 KB Output is correct
6 Correct 125 ms 23980 KB Output is correct
7 Correct 87 ms 28064 KB Output is correct
8 Correct 86 ms 24124 KB Output is correct
9 Correct 91 ms 17512 KB Output is correct
10 Correct 138 ms 23196 KB Output is correct
11 Correct 107 ms 22224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 3 ms 5172 KB Output is correct
6 Correct 3 ms 5168 KB Output is correct
7 Correct 3 ms 5176 KB Output is correct
8 Correct 3 ms 5076 KB Output is correct
9 Correct 3 ms 5236 KB Output is correct
10 Correct 3 ms 5172 KB Output is correct
11 Correct 3 ms 5204 KB Output is correct
12 Correct 4 ms 5204 KB Output is correct
13 Correct 3 ms 5164 KB Output is correct
14 Correct 3 ms 5196 KB Output is correct
15 Correct 2 ms 4948 KB Output is correct
16 Correct 2 ms 4948 KB Output is correct
17 Correct 113 ms 20244 KB Output is correct
18 Correct 105 ms 23384 KB Output is correct
19 Correct 105 ms 24020 KB Output is correct
20 Correct 115 ms 24648 KB Output is correct
21 Correct 110 ms 24640 KB Output is correct
22 Correct 129 ms 24768 KB Output is correct
23 Correct 121 ms 25992 KB Output is correct
24 Correct 79 ms 27328 KB Output is correct
25 Correct 81 ms 27076 KB Output is correct
26 Correct 108 ms 23256 KB Output is correct
27 Correct 113 ms 22156 KB Output is correct
28 Correct 100 ms 22432 KB Output is correct
29 Correct 93 ms 23728 KB Output is correct
30 Correct 82 ms 22896 KB Output is correct
31 Correct 2 ms 4948 KB Output is correct
32 Correct 136 ms 19176 KB Output is correct
33 Correct 161 ms 23840 KB Output is correct
34 Correct 107 ms 23744 KB Output is correct
35 Correct 99 ms 22168 KB Output is correct
36 Correct 140 ms 23668 KB Output is correct
37 Correct 123 ms 23740 KB Output is correct
38 Correct 144 ms 23668 KB Output is correct
39 Correct 76 ms 22804 KB Output is correct
40 Correct 97 ms 23100 KB Output is correct
41 Correct 111 ms 22260 KB Output is correct
42 Correct 3 ms 4948 KB Output is correct
43 Correct 147 ms 20284 KB Output is correct
44 Correct 142 ms 24612 KB Output is correct
45 Correct 144 ms 24744 KB Output is correct
46 Correct 130 ms 24760 KB Output is correct
47 Correct 125 ms 23980 KB Output is correct
48 Correct 87 ms 28064 KB Output is correct
49 Correct 86 ms 24124 KB Output is correct
50 Correct 91 ms 17512 KB Output is correct
51 Correct 138 ms 23196 KB Output is correct
52 Correct 107 ms 22224 KB Output is correct
53 Correct 2 ms 4948 KB Output is correct
54 Correct 2 ms 4948 KB Output is correct
55 Correct 2 ms 4948 KB Output is correct
56 Correct 3 ms 5204 KB Output is correct
57 Correct 3 ms 5172 KB Output is correct
58 Correct 3 ms 5204 KB Output is correct
59 Correct 3 ms 5172 KB Output is correct
60 Correct 3 ms 5076 KB Output is correct
61 Correct 3 ms 5204 KB Output is correct
62 Correct 3 ms 5172 KB Output is correct
63 Correct 3 ms 5204 KB Output is correct
64 Correct 3 ms 5204 KB Output is correct
65 Correct 5 ms 5196 KB Output is correct
66 Correct 3 ms 5172 KB Output is correct
67 Correct 112 ms 24756 KB Output is correct
68 Correct 105 ms 23376 KB Output is correct
69 Correct 107 ms 24056 KB Output is correct
70 Correct 120 ms 24644 KB Output is correct
71 Correct 120 ms 24628 KB Output is correct
72 Correct 122 ms 24752 KB Output is correct
73 Correct 118 ms 25888 KB Output is correct
74 Correct 92 ms 27280 KB Output is correct
75 Correct 89 ms 27180 KB Output is correct
76 Correct 107 ms 23276 KB Output is correct
77 Correct 97 ms 22176 KB Output is correct
78 Correct 93 ms 22412 KB Output is correct
79 Correct 100 ms 23700 KB Output is correct
80 Correct 75 ms 22920 KB Output is correct
81 Correct 131 ms 23600 KB Output is correct
82 Correct 151 ms 23692 KB Output is correct
83 Correct 103 ms 23720 KB Output is correct
84 Correct 95 ms 22172 KB Output is correct
85 Correct 157 ms 23692 KB Output is correct
86 Correct 124 ms 23764 KB Output is correct
87 Correct 118 ms 23744 KB Output is correct
88 Correct 98 ms 23064 KB Output is correct
89 Correct 111 ms 22212 KB Output is correct
90 Correct 142 ms 24596 KB Output is correct
91 Correct 132 ms 24604 KB Output is correct
92 Correct 140 ms 24872 KB Output is correct
93 Correct 122 ms 24736 KB Output is correct
94 Correct 125 ms 24124 KB Output is correct
95 Correct 94 ms 28032 KB Output is correct
96 Correct 91 ms 24076 KB Output is correct
97 Correct 79 ms 17456 KB Output is correct
98 Correct 123 ms 23240 KB Output is correct
99 Correct 104 ms 22212 KB Output is correct
100 Correct 43 ms 11604 KB Output is correct
101 Correct 153 ms 24728 KB Output is correct
102 Correct 122 ms 22052 KB Output is correct
103 Correct 143 ms 22812 KB Output is correct
104 Correct 156 ms 24476 KB Output is correct