Submission #218080

#TimeUsernameProblemLanguageResultExecution timeMemory
218080brainwarego트리 (KOI16_tree)C11
Compilation error
0 ms0 KiB
#include <stdio.h> #define LM 200010 int N, Q, par[LM], group[LM], gn; int used[LM], gtop[LM] = {1}; struct Node{ int node; Node*next; }adj[LM], buf[LM*3]; int bCnt; struct Queue{ Node*now; Node* hasNext(){ while(now->next && used[now->next->node]){ now->next = now->next->next; } now = now->next; return now; } }xQue[LM], yQue[LM]; int xf, xe, yf, ye; void push_adj(int s, int e){ buf[bCnt] = {e, adj[s].next}; adj[s].next = buf + bCnt++; } void reGroup(int k){ group[k] = gn; for(Node*p = adj+k;p->next;){ if(used[p->next->node]){ p->next = p->next->next; } else{ reGroup(p->next->node); p = p->next; } } } void split(int a, int b){ if(a==0) return; par[b] = 0; used[b] = 1; a = gtop[group[a]]; int flag = 0; xf = xe = yf = ye = 0; xQue[xe++] = {adj+a}; yQue[ye++] = {adj+b}; while(1){ while(xf<xe && !xQue[xf].hasNext()) ++xf; if(xf >= xe) break; xQue[xe++] = {adj + xQue[xf].now->node}; while(yf<ye && !yQue[yf].hasNext()) ++yf; if(yf >= ye){ flag = 1; break; } yQue[ye++] = {adj + yQue[yf].now->node}; } gn++; if(flag){ gtop[gn] = b; reGroup(b); } else{ gtop[group[a]] = b; gtop[gn] = a; reGroup(a); } } int main(){ scanf("%d %d", &N, &Q); int i, b, c, d; for(i=2;i<=N;++i){ scanf("%d", &b); par[i] = b; push_adj(b, i); } for(i=0;i<Q;++i){ scanf("%d %d %d", &b, &c, &d); int flag = group[b]==group[c]; puts(flag? "YES":"NO"); if(d){ if(flag) split(par[b], b); else split(par[c], c); } } return 0; }

Compilation message (stderr)

tree.c:8:5: error: unknown type name 'Node'
     Node*next;
     ^~~~
tree.c:13:5: error: unknown type name 'Node'
     Node*now;
     ^~~~
tree.c:14:5: error: unknown type name 'Node'
     Node* hasNext(){
     ^~~~
tree.c:14:20: error: expected ':', ',', ';', '}' or '__attribute__' before '{' token
     Node* hasNext(){
                    ^
tree.c: In function 'push_adj':
tree.c:25:17: error: expected expression before '{' token
     buf[bCnt] = {e, adj[s].next};
                 ^
tree.c:26:17: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
     adj[s].next = buf + bCnt++;
                 ^
tree.c: In function 'reGroup':
tree.c:31:9: error: unknown type name 'Node'; use 'struct' keyword to refer to the type
     for(Node*p = adj+k;p->next;){
         ^~~~
         struct 
tree.c:31:18: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     for(Node*p = adj+k;p->next;){
                  ^~~
tree.c:31:25: error: request for member 'next' in something not a structure or union
     for(Node*p = adj+k;p->next;){
                         ^~
tree.c:32:18: error: request for member 'next' in something not a structure or union
         if(used[p->next->node]){
                  ^~
tree.c:33:14: error: request for member 'next' in something not a structure or union
             p->next = p->next->next;
              ^~
tree.c:33:24: error: request for member 'next' in something not a structure or union
             p->next = p->next->next;
                        ^~
tree.c:36:22: error: request for member 'next' in something not a structure or union
             reGroup(p->next->node);
                      ^~
tree.c:37:18: error: request for member 'next' in something not a structure or union
             p = p->next;
                  ^~
tree.c: In function 'split':
tree.c:50:18: error: expected expression before '{' token
     xQue[xe++] = {adj+a};
                  ^
tree.c:51:18: error: expected expression before '{' token
     yQue[ye++] = {adj+b};
                  ^
tree.c:53:33: error: 'struct Queue' has no member named 'hasNext'
         while(xf<xe && !xQue[xf].hasNext())
                                 ^
tree.c:57:22: error: expected expression before '{' token
         xQue[xe++] = {adj + xQue[xf].now->node};
                      ^
tree.c:59:33: error: 'struct Queue' has no member named 'hasNext'
         while(yf<ye && !yQue[yf].hasNext())
                                 ^
tree.c:65:22: error: expected expression before '{' token
         yQue[ye++] = {adj + yQue[yf].now->node};
                      ^
tree.c: In function 'main':
tree.c:80:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &Q);
     ^~~~~~~~~~~~~~~~~~~~~~
tree.c:83:9: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &b);
         ^~~~~~~~~~~~~~~
tree.c:89:9: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d", &b, &c, &d);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~