int main(int argc, char *argv[]) { int T = 0, test_case; int i, j, p, c, mp, mc; //freopen("mytest.txt", "r", stdin); freopen("A-large.in", "r", stdin); //freopen("A-small.in", "r", stdin); freopen("ouput.txt", "w", stdout); scanf("%d\n", &test_case); for (T = 0; T < test_case; T++) { scanf("%d %d\n", &N, &M); if (N < 2 || M < 1 || N > MAXN || N > MAXM) continue; for (i = 0; i <= MAXM; i++) path[i] = 0; path[1] = path[0] = 1; for (i = 0; i < N-1; i++) { scanf("%d %d", &p, &c); path[c] = p; } for(i = 0; i < M; i++) { scanf("%d %d\n", &mp, &mc); printf("%d\n", is_in_path(mp, mc)); } } return 0; }
void menu_create (GtkWidget *menu, GSList *list, char *target, int check_path) { struct popup *pop; GtkWidget *tempmenu = menu, *subitem = NULL; int childcount = 0; submenu_list = g_slist_prepend (0, menu); while (list) { pop = (struct popup *) list->data; if (!g_ascii_strncasecmp (pop->name, "SUB", 3)) { childcount = 0; tempmenu = menu_quick_sub (pop->cmd, tempmenu, &subitem, XCMENU_DOLIST, -1); } else if (!g_ascii_strncasecmp (pop->name, "TOGGLE", 6)) { childcount++; menu_toggle_item (pop->name + 7, tempmenu, toggle_cb, pop->cmd, cfg_get_bool (pop->cmd)); } else if (!g_ascii_strncasecmp (pop->name, "ENDSUB", 6)) { /* empty sub menu due to no programs in PATH? */ if (check_path && childcount < 1) gtk_widget_destroy (subitem); subitem = NULL; if (tempmenu != menu) tempmenu = menu_quick_endsub (); /* If we get here and tempmenu equals menu that means we havent got any submenus to exit from */ } else if (!g_ascii_strncasecmp (pop->name, "SEP", 3)) { menu_quick_item (0, 0, tempmenu, XCMENU_SHADED, 0, 0); } else { if (!check_path || pop->cmd[0] != '!') { menu_quick_item (pop->cmd, pop->name, tempmenu, 0, target, 0); /* check if the program is in path, if not, leave it out! */ } else if (is_in_path (pop->cmd)) { childcount++; menu_quick_item (pop->cmd, pop->name, tempmenu, 0, target, 0); } } list = list->next; } /* Let's clean up the linked list from mem */ while (submenu_list) submenu_list = g_slist_remove (submenu_list, submenu_list->data); }
void builtin_command_exec_verbose(t_argparser_result *result, t_shenv *shenv) { t_lst *remainders_copy; char *cmd_name; int ret; remainders_copy = twl_lst_copy(result->remainders, NULL); ret = 1; while ((cmd_name = twl_lst_pop_front(remainders_copy))) { if (is_an_alias(cmd_name, shenv)) ret = 0; else if (is_a_function(cmd_name, shenv)) ret = 0; else if (is_a_builtin(cmd_name, shenv)) ret = 0; else if (is_in_path(cmd_name, shenv)) ret = 0; } twl_lst_del(remainders_copy, NULL); shenv->last_exit_code = ret; }