6 Commits

Author SHA1 Message Date
unlockable
5b6faf4409 Only MLE 2023-11-20 19:37:30 +08:00
unlockable
615133f12a MLE and WA. 2023-11-20 19:19:45 +08:00
unlockable
266b237108 MLE and WA 2023-11-13 19:55:54 +08:00
unlockable
6af94e27b0 90. 2023-11-13 19:55:54 +08:00
unlockable
77eb4765be Use long long. 2023-11-13 19:55:54 +08:00
unlockable
c07330c8af Read in data before anything started. 2023-11-05 16:33:25 +08:00
3 changed files with 147 additions and 8 deletions

View File

@@ -4,6 +4,8 @@
// 'Natural count' is the name of the node when all the nodes in the tree is
// alive. xxx_num denotes the count as the question described.
// SEE ALSO BRANCH 04_02 WITH A CORRECT IMPLEMENTATION
int ans[200] = {0};
long long dead_nodes_num[105] = {0};
int total_dead_nodes = 0;
@@ -16,7 +18,7 @@ struct SeveralContinuedDeadNode {
};
struct SearchResult {
int next_ans_pos; // pos in the ans[] array.
int next_ans_pos; // pos in the ans[] array.
long long count_in_father_line; // natural count.
};
@@ -38,7 +40,8 @@ SearchResult find_node(long long target, long long start_num, int next_dead_node
}
else {
all_dead = false;
long long total_spawned_after = spawned_node_max_num + upper_line[upper_line_iter].length * 2;
long long total_spawned_after =
spawned_node_max_num + upper_line[upper_line_iter].length * 2;
while (dead_nodes_num[next_dead_node_num_ptr] <= total_spawned_after &&
next_dead_node_num_ptr < total_dead_nodes) {
if (dead_nodes_num[next_dead_node_num_ptr] - spawned_node_max_num > 1) {
@@ -123,26 +126,34 @@ SearchResult find_node(long long target, long long start_num, int next_dead_node
int main() {
scanf("%d %d", &total_dead_nodes, &total_target_nodes);
for (int i = 0; i < total_dead_nodes; i++) {
scanf("%d", &dead_nodes_num[i]);
scanf("%lld", &dead_nodes_num[i]);
}
for (int i = 0; i < total_target_nodes; i++) {
scanf("%lld", &target_nodes_num[i]);
}
if (dead_nodes_num[0] == 1) {
for (int i = 0; i < total_target_nodes; i++) {
printf("0\n");
if (target_nodes_num[i] == 1) {
printf("1\n");
continue;
}
else {
printf("0\n");
}
}
return 0;
}
else {
long long current_target = 0;
SeveralContinuedDeadNode firstline = SeveralContinuedDeadNode{ALIVE, 1};
for (int i = 0; i < total_target_nodes; i++) {
scanf("%lld", &current_target);
SearchResult result = find_node(current_target, 2, 0, &firstline, 1, 2);
SearchResult result = find_node(target_nodes_num[i], 2, 0, &firstline, 1, 2);
if (result.count_in_father_line == -1) {
printf("0\n");
}
else {
printf("1 ");
for (int j = result.next_ans_pos - 1; j >= 0; j--) {
printf("%d ", ans[j]);
printf("%lld ", ans[j]);
}
printf("\n");
}

124
2023205/main.cpp Normal file
View File

@@ -0,0 +1,124 @@
#include <stdio.h>
// 并查集。并查集只关注双向连通性。
struct Edge {
int next;
unsigned short end;
bool used_in_dfs;
};
Edge edges[1050000];
char nodes_visited[65540];
int head[65540], len;
int add_edge(int start, int terminal) {
edges[++len].end = terminal;
edges[len].next = head[start];
head[start] = len;
return 0;
}
int dfs(int start) {
if (nodes_visited[start] >= 1) {
// nodes_visited[start] = 2;
return 0;
}
nodes_visited[start] = 1;
for (int j = head[start]; j != 0; j = edges[j].next) {
edges[j].used_in_dfs = dfs(edges[j].end);
}
return 1;
}
int dfs_with_dead_edge(int start, int dead_edge_start, int dead_edge_end) {
if (nodes_visited[start] >= 1) {
return 0;
}
nodes_visited[start] = 1;
if (start == dead_edge_start) {
for (int j = head[start]; j != 0; j = edges[j].next) {
if (edges[j].end == dead_edge_end) {
continue;
}
dfs_with_dead_edge(edges[j].end, dead_edge_start, dead_edge_end);
}
return 0;
}
for (int j = head[start]; j != 0; j = edges[j].next) {
dfs_with_dead_edge(edges[j].end, dead_edge_start, dead_edge_end);
}
return 0;
}
int main() {
int N, M;
scanf("%d %d", &N, &M);
for (int start = 0; start < N; start++) {
int edge_count;
scanf("%d", &edge_count);
for (int j = 0; j < edge_count; j++) {
int terminal;
scanf("%d", &terminal);
add_edge(start, terminal);
}
}
dfs(0);
for (int i = 0; i < N; i++) {
if (nodes_visited[i] < 1) {
// Not connected!
for (int j = 0; j <= M; j++) {
printf("0\n");
}
return 0;
}
}
printf("1\n");
// for (int i = 0; i < M; i++) {
// int start, end;
// scanf("%d %d", &start, &end);
// if (nodes_visited[end] == 2) {
// printf("1\n");
// }
// else {
// printf("0\n");
// }
// }
for (int i = 0; i < M; i++) {
int start, end;
scanf("%d %d", &start, &end);
for (int j = head[start]; j != 0; j = edges[j].next) {
if (edges[j].end == end) {
if (edges[j].used_in_dfs) {
for (int k = 0; k < N; k++) {
nodes_visited[k] = 0;
}
dfs_with_dead_edge(0, start, end);
bool connected = true;
for (int k = 0; k < N; k++) {
if (nodes_visited[k] < 1) {
printf("0\n");
connected = false;
break;
}
}
if (connected) {
printf("1\n");
}
}
else {
printf("1\n");
}
break;
}
}
}
return 0;
}

4
2023205/testdat.txt Normal file
View File

@@ -0,0 +1,4 @@
4 2 2 1 2 2 2 3 0 1 0 0 1 0 2
4 1 1 1 2 2 3 2 1 3 2 1 2 0 1