회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
C언어 런타임 입니다.
1325번 - 효율적인 해킹
blutics
5년 전
0
계속 런타임 에러가 나는데......
통과못하는 테스트 케이스라도 알려주세요.
#include<stdio.h> #include<stdlib.h> int row; int n; int* table; int** arr; typedef struct List{ int count; struct Node* head; struct Node* tail; }List; typedef struct Node{ int number; struct Node* previous; struct Node* next; struct List* connections; }Node; Node* array; List* makeList(); Node* makeNode(int number){ Node* new = (Node*)malloc(sizeof(Node)); new->number=number; new->previous=NULL; new->next=NULL; new->connections=makeList(); return new; } void addNode(List* list, int number){ if(list->head==NULL){ list->head=makeNode(number); list->head->next=NULL; list->tail=list->head; }else{ list->tail->next=makeNode(number); list->tail=list->tail->next; list->tail->next=NULL; } list->count++; } void delNode(List* list, Node* current){ if(current->previous==NULL){ list->head=current->next; if(list->head!=NULL){ list->head->previous=NULL; }else{ list->tail=NULL; } }else if(current->next==NULL){ list->tail=current->previous; list->tail->next=NULL; }else{ current->previous->next=current->next; current->next->previous=current->previous; } free(current); list->count--; } List* makeList(){ List* new = (List*)malloc(sizeof(List)); new->head = NULL; new->tail = NULL; new->count = 0; return new; } void freeList(List* list){ Node* tmp = list->head; while(list->count!=0){ delNode(list, tmp); tmp=tmp->next; } free(list); } int determine(List* list, int number){ Node* tmp = list->head; while(tmp!=NULL){ if(tmp->number==number){ return 1; } tmp=tmp->next; } return 0; } void emptyList(List* list){ Node* tmp=list->head; while(tmp!=NULL){ delNode(list, tmp); tmp=list->head; } } int checkDepth(Node* node){ List* checkingList = makeList(); List* checkedList = makeList(); List* nextList = makeList(); Node* tmp; Node* ntmp; List* ltmp; int depth = 0; addNode(nextList, node->number); if(node->connections->count==0){ return 1; } while(nextList->count!=0){ checkingList = nextList; nextList = makeList(); tmp=checkingList->head; addNode(checkedList, tmp->number); while(tmp!=NULL){ ltmp=array[tmp->number].connections; ntmp=ltmp->head; while(ntmp!=NULL){ if(!determine(checkedList, ntmp->number)){ addNode(checkedList, ntmp->number); addNode(nextList, ntmp->number); } ntmp=ntmp->next; } tmp=tmp->next; } freeList(checkingList); depth++; } return depth; } int* answer(int number){ int* arr = (int*)malloc(number*4); for(int i=0;i<number;i++){ arr[i]=checkDepth(&array[i]); } return arr; } void init(){ row=0; n=0; scanf("%d %d", &n, &row); arr = (int**)malloc(sizeof(int*)*row); for(int i=0;i<row;i++){ arr[i]=(int*)malloc(sizeof(int)*2); } for(int i=0;i<row;i++){ scanf("%d %d", &arr[i][0], &arr[i][1]); } array = (Node*)malloc(sizeof(Node*)*(n+1)); for(int i = 0;i<(n+1);i++){ array[i]=*(makeNode(i)); } } void setData(){ List* tmp; for(int i=0;i<row;i++){ tmp=array[arr[i][1]].connections; addNode(tmp, arr[i][0]); } } int main(){ init(); setData(); table = answer(n+1); List* result=makeList(); int MAX=0; for(int i=0;i<n+1;i++){ if(table[i]>MAX){ MAX=table[i]; } } for(int i=1;i<n+1;i++){ if(table[i]==MAX){ addNode(result, i); } } Node* tmp=result->head; while(tmp!=NULL){ if(tmp->next!=NULL){ printf("%d ", tmp->number); }else{ printf("%d", tmp->number); } tmp=tmp->next; } return 0; }
댓글을 작성하려면
로그인
해야 합니다.
blutics 5년 전
계속 런타임 에러가 나는데......
통과못하는 테스트 케이스라도 알려주세요.