Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf6e6b0c86
|
||
|
|
9fd8ea1918
|
||
|
|
f55fb12e50
|
@@ -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", ¤t_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");
|
||||
}
|
||||
|
||||
71
2023205/main.cpp
Normal file
71
2023205/main.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <stdio.h>
|
||||
// 并查集。并查集只关注双向连通性。
|
||||
|
||||
struct Edge {
|
||||
unsigned short end;
|
||||
int next;
|
||||
};
|
||||
|
||||
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) {
|
||||
dfs(edges[j].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");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user