Submission #1098898

# Submission time Handle Problem Language Result Execution time Memory
1098898 2024-10-10T09:54:21 Z NDT134 Stranded Far From Home (BOI22_island) C++14
100 / 100
254 ms 42948 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
using pi = pair<int, int>;
using ll = long long;

vector<int> p, l; vector<ll> sm;
vector<vector<int>> w;

void find(int a)
{
	vector<int> v;
	while (p[a] != a)
	{
		v.push_back(a);
		a = p[a];
	}
	for (int x : v)
	{
		p[x] = a;
	}
}

int main() {
	int n, M; cin >> n >> M;
	sm.resize(n); p.resize(n); l.resize(n); w.resize(n);
	vector<vector<int>> g(n);
	vector<ll> s(n);
	vector<pi> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
		p[i] = i; l[i] = 1; w[i].push_back(i); sm[i] = s[i];
		v[i] = { s[i],i };
	}
	for (int i = 0; i < M; i++)
	{
		int a, b; cin >> a >> b; a--; b--;
		g[a].push_back(b); g[b].push_back(a);
	}

	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++)
	{
		int x = v[i].second;

		map<int, int> m;
		vector<int> a;
		for (int y : g[x])
		{
			if (s[y] < s[x] || (s[y] == s[x] && y < x))
			{
				find(y);
				if (!m[p[y]])
				{
					m[p[y]] = 1;
					a.push_back(p[y]);
				}
			}
		}
		if (!a.empty())
		{
			int j = a[0], k = l[a[0]];
			for (int y : a)
			{
				if (l[y] > k)
				{
					j = y; k = l[y];
				}
			}

			if (sm[j] < s[x])
			{
				w[j].clear();
			}
			w[j].push_back(x); l[j]++; sm[j] += s[x];
			for (int y : a)
			{
				if (y != j)
				{
					l[j] += l[y]; sm[j] += sm[y];
					if (sm[y] >= s[x])
					{
						for (int z : w[y])
						{
							w[j].push_back(z);
						}
					}
				}
			}

			for (int y : a)
			{
				p[y] = j;
			}
			p[x] = j;
		}
	}

	vector<int> r(n);
	for (int i = 0; i < n; i++)
	{
		if (p[i] == i)
		{
			for (int y : w[i])
			{
				r[y] = 1;
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		cout << r[i];
	}
	cout << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 700 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 179 ms 30264 KB Output is correct
4 Correct 162 ms 33404 KB Output is correct
5 Correct 193 ms 35540 KB Output is correct
6 Correct 203 ms 36920 KB Output is correct
7 Correct 212 ms 36644 KB Output is correct
8 Correct 190 ms 34760 KB Output is correct
9 Correct 190 ms 38084 KB Output is correct
10 Correct 236 ms 42948 KB Output is correct
11 Correct 168 ms 34488 KB Output is correct
12 Correct 166 ms 33616 KB Output is correct
13 Correct 142 ms 33252 KB Output is correct
14 Correct 158 ms 33352 KB Output is correct
15 Correct 175 ms 34808 KB Output is correct
16 Correct 143 ms 33732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 232 ms 33164 KB Output is correct
3 Correct 245 ms 37444 KB Output is correct
4 Correct 196 ms 34880 KB Output is correct
5 Correct 156 ms 33484 KB Output is correct
6 Correct 224 ms 37708 KB Output is correct
7 Correct 189 ms 34768 KB Output is correct
8 Correct 192 ms 34748 KB Output is correct
9 Correct 146 ms 33740 KB Output is correct
10 Correct 172 ms 33748 KB Output is correct
11 Correct 177 ms 33480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 240 ms 30776 KB Output is correct
3 Correct 237 ms 35528 KB Output is correct
4 Correct 240 ms 36880 KB Output is correct
5 Correct 235 ms 37576 KB Output is correct
6 Correct 213 ms 34592 KB Output is correct
7 Correct 215 ms 39172 KB Output is correct
8 Correct 144 ms 33268 KB Output is correct
9 Correct 157 ms 19024 KB Output is correct
10 Correct 192 ms 36932 KB Output is correct
11 Correct 186 ms 33560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 700 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 179 ms 30264 KB Output is correct
18 Correct 162 ms 33404 KB Output is correct
19 Correct 193 ms 35540 KB Output is correct
20 Correct 203 ms 36920 KB Output is correct
21 Correct 212 ms 36644 KB Output is correct
22 Correct 190 ms 34760 KB Output is correct
23 Correct 190 ms 38084 KB Output is correct
24 Correct 236 ms 42948 KB Output is correct
25 Correct 168 ms 34488 KB Output is correct
26 Correct 166 ms 33616 KB Output is correct
27 Correct 142 ms 33252 KB Output is correct
28 Correct 158 ms 33352 KB Output is correct
29 Correct 175 ms 34808 KB Output is correct
30 Correct 143 ms 33732 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 232 ms 33164 KB Output is correct
33 Correct 245 ms 37444 KB Output is correct
34 Correct 196 ms 34880 KB Output is correct
35 Correct 156 ms 33484 KB Output is correct
36 Correct 224 ms 37708 KB Output is correct
37 Correct 189 ms 34768 KB Output is correct
38 Correct 192 ms 34748 KB Output is correct
39 Correct 146 ms 33740 KB Output is correct
40 Correct 172 ms 33748 KB Output is correct
41 Correct 177 ms 33480 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 240 ms 30776 KB Output is correct
44 Correct 237 ms 35528 KB Output is correct
45 Correct 240 ms 36880 KB Output is correct
46 Correct 235 ms 37576 KB Output is correct
47 Correct 213 ms 34592 KB Output is correct
48 Correct 215 ms 39172 KB Output is correct
49 Correct 144 ms 33268 KB Output is correct
50 Correct 157 ms 19024 KB Output is correct
51 Correct 192 ms 36932 KB Output is correct
52 Correct 186 ms 33560 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 2 ms 604 KB Output is correct
57 Correct 2 ms 604 KB Output is correct
58 Correct 2 ms 604 KB Output is correct
59 Correct 2 ms 604 KB Output is correct
60 Correct 2 ms 604 KB Output is correct
61 Correct 2 ms 604 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 2 ms 684 KB Output is correct
64 Correct 2 ms 604 KB Output is correct
65 Correct 2 ms 604 KB Output is correct
66 Correct 2 ms 604 KB Output is correct
67 Correct 207 ms 34580 KB Output is correct
68 Correct 154 ms 33484 KB Output is correct
69 Correct 200 ms 35628 KB Output is correct
70 Correct 204 ms 36812 KB Output is correct
71 Correct 219 ms 36644 KB Output is correct
72 Correct 207 ms 34756 KB Output is correct
73 Correct 198 ms 37836 KB Output is correct
74 Correct 248 ms 42948 KB Output is correct
75 Correct 177 ms 34632 KB Output is correct
76 Correct 180 ms 33616 KB Output is correct
77 Correct 160 ms 33232 KB Output is correct
78 Correct 169 ms 33488 KB Output is correct
79 Correct 185 ms 34816 KB Output is correct
80 Correct 148 ms 33924 KB Output is correct
81 Correct 238 ms 37384 KB Output is correct
82 Correct 229 ms 37528 KB Output is correct
83 Correct 206 ms 34768 KB Output is correct
84 Correct 166 ms 33484 KB Output is correct
85 Correct 243 ms 37712 KB Output is correct
86 Correct 201 ms 34916 KB Output is correct
87 Correct 220 ms 34764 KB Output is correct
88 Correct 178 ms 33668 KB Output is correct
89 Correct 186 ms 33484 KB Output is correct
90 Correct 252 ms 35272 KB Output is correct
91 Correct 238 ms 35532 KB Output is correct
92 Correct 235 ms 36788 KB Output is correct
93 Correct 223 ms 37572 KB Output is correct
94 Correct 197 ms 34528 KB Output is correct
95 Correct 208 ms 39352 KB Output is correct
96 Correct 138 ms 33236 KB Output is correct
97 Correct 126 ms 19100 KB Output is correct
98 Correct 179 ms 36808 KB Output is correct
99 Correct 195 ms 33480 KB Output is correct
100 Correct 70 ms 4948 KB Output is correct
101 Correct 254 ms 36044 KB Output is correct
102 Correct 204 ms 28356 KB Output is correct
103 Correct 206 ms 29536 KB Output is correct
104 Correct 242 ms 34500 KB Output is correct