답안 #970509

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970509 2024-04-26T16:12:43 Z yellowtoad Stranded Far From Home (BOI22_island) C++17
10 / 100
412 ms 58864 KB
#include <iostream>
#include <vector>
#include <algorithm>
#define f first
#define s second
using namespace std;

long long n, m, p[200010], sum[200010], vis[200010], scc[200010], cnt, in[200010];
pair<long long,int> a[200010];
vector<int> edge[200010], ed[200010], rev[200010], post;

int dsu(int u) {
	if (u == p[u]) return u;
	return p[u] = dsu(p[u]);
}

void dfs(int u) {
	vis[u] = 1;
	for (int i = 0; i < ed[u].size(); i++) if (!vis[ed[u][i]]) dfs(ed[u][i]);
	post.push_back(u);
}

void rdfs(int u) {
	scc[u] = cnt;
	for (int i = 0; i < rev[u].size(); i++) if (!scc[rev[u][i]]) rdfs(rev[u][i]);
}

int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].f;
		a[i].s = p[i] = i;
		sum[i] = a[i].f;
	}
	sort(a+1,a+n+1);
	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) {
		int u = a[i].s;
		vis[u] = 1;
		for (int j = 0; j < edge[u].size(); j++) {
			if (!vis[edge[u][j]]) continue;
			ed[u].push_back(edge[u][j]);
			rev[edge[u][j]].push_back(u);
			if (dsu(u) != dsu(edge[u][j])) {
				if (sum[dsu(edge[u][j])] >= a[i].f) ed[edge[u][j]].push_back(u), rev[u].push_back(edge[u][j]);;
				sum[dsu(u)] += sum[dsu(edge[u][j])];
				p[dsu(edge[u][j])] = p[dsu(u)];
			}
		}
	}
	for (int i = 1; i <= n; i++) vis[i] = 0;
	for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i);
	for (int i = post.size()-1; i >= 0; i--) {
		if (!scc[post[i]]) {
			++cnt;
			rdfs(post[i]);
		}
	}
	for (int i = 1; i <= n; i++) for (int j = 0; j < ed[i].size(); j++) if (scc[i] != scc[ed[i][j]]) in[scc[ed[i][j]]]++;
	for (int i = 1; i <= n; i++) cout << (in[scc[i]] == 0);
	cout << endl;
}

Compilation message

island.cpp: In function 'void dfs(int)':
island.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  for (int i = 0; i < ed[u].size(); i++) if (!vis[ed[u][i]]) dfs(ed[u][i]);
      |                  ~~^~~~~~~~~~~~~~
island.cpp: In function 'void rdfs(int)':
island.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for (int i = 0; i < rev[u].size(); i++) if (!scc[rev[u][i]]) rdfs(rev[u][i]);
      |                  ~~^~~~~~~~~~~~~~~
island.cpp: In function 'int main()':
island.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int j = 0; j < edge[u].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~~
island.cpp:64:49: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for (int i = 1; i <= n; i++) for (int j = 0; j < ed[i].size(); j++) if (scc[i] != scc[ed[i][j]]) in[scc[ed[i][j]]]++;
      |                                               ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23132 KB Output is correct
2 Correct 4 ms 23172 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Incorrect 6 ms 23384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23132 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 244 ms 51440 KB Output is correct
4 Correct 230 ms 52140 KB Output is correct
5 Correct 284 ms 46532 KB Output is correct
6 Correct 331 ms 47300 KB Output is correct
7 Correct 295 ms 47244 KB Output is correct
8 Correct 341 ms 49868 KB Output is correct
9 Correct 231 ms 46280 KB Output is correct
10 Correct 192 ms 44160 KB Output is correct
11 Correct 202 ms 50756 KB Output is correct
12 Correct 300 ms 48616 KB Output is correct
13 Correct 206 ms 57544 KB Output is correct
14 Correct 243 ms 57872 KB Output is correct
15 Correct 279 ms 58864 KB Output is correct
16 Correct 201 ms 57964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Incorrect 348 ms 48788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21080 KB Output is correct
2 Incorrect 412 ms 48080 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 23132 KB Output is correct
2 Correct 4 ms 23172 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Incorrect 6 ms 23384 KB Output isn't correct
5 Halted 0 ms 0 KB -