회원가입
로그인
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
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
반례가 있나요..? 틀렸습니다.... 주석있어용 !
2416번 - 문
gks10101
2년 전
0
가독성 좋게 정리한 코드입니다... 4프로에서 틀렸다는데 뭐가 문제일까요...
#pragma warning (disable: 4996) #define _CRT_NO_SECURE_WARNINGS #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> struct node { int index; struct node* next; }; struct node nodepool[500005]; struct node head[2 * 500005]; int nodepoolcnt = 0; int stack[2 * 500005]; int dfsn[2 * 500005]; int finish[2 * 500005]; int sn[2 * 500005]; int top = 0, cnt = 0, SN = 1; int n, m, a, b, c, d; int ans[500005]; int real(int x) { //켜진 것 return x * 2 - 1; } int fake(int x) { //꺼진 것 return (x - 1) * 2; } void push(int x,int y) { nodepool[nodepoolcnt].index = y; nodepool[nodepoolcnt].next = head[x].next; head[x].next = &nodepool[nodepoolcnt++]; } void init() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d %d %d %d", &a, &b, &c, &d); //0이면 꺼져야 닫긴거 1이면 켜야 닫긴거 if (b == 0) { if (d == 0) { //a가 꺼지거나 c가 꺼지거나 push(real(c), fake(a)); push(real(a), fake(c)); } else { //a가 꺼지거나 c가 켜지거나 push(fake(c), fake(a)); push(real(a), real(c)); } } else { if (d == 0) { //a가 켜지거나 c가 꺼지거나 push(real(c), real(a)); push(fake(a), fake(c)); } else { //a가 켜지거나 c가 켜지거나 push(fake(c), real(a)); push(fake(a), real(c)); } } } } int min(int g, int h) { return (g < h) ? g : h; } int dfs(int x) { dfsn[x] = ++cnt; stack[top++] = x; int result = dfsn[x]; struct node* cursor = head[x].next; while (cursor != NULL) { if (dfsn[cursor->index] == 0) result = min(result, dfs(cursor->index)); else if (finish[cursor->index] == 0) result = min(result, dfsn[cursor->index]); cursor = cursor->next; } if (result == dfsn[x]) { while (1) { int imsi = stack[--top]; sn[imsi] = SN; finish[imsi] = 1; if (x == imsi) break; } SN++; } return result; } typedef struct SCC { int index; int snnum; }SCC; SCC scc[500005]; int compare(const void* A, const void* B) { SCC a = *(SCC*)A; SCC b = *(SCC*)B; if (a.snnum > b.snnum) return -1; else return 1; } void sort() { for (int i = 0; i < 2 * m; i++) { scc[i].index = i; scc[i].snnum = sn[i]; } qsort(scc, 2 * m, sizeof(SCC), compare); for (int i = 0; i < 2 * m; i++) { printf("%d - %d에속함\n", scc[i].index, scc[i].snnum); } for (int i = 0; i < 2 * m; i++) { int curr = scc[i].index; if (ans[curr / 2] == -1) { if (curr % 2 == 0) { ans[curr / 2] = 1; } else { ans[curr / 2] = 0; } } } } int main() { init(); for (int i = 0; i < 2 * m; i++) { if (dfsn[i] == 0) dfs(i); } int flag = 0; for (int i = 0; i < m; i++) { if (sn[i * 2] == sn[i * 2 + 1]) { flag = 1; break; } } if (flag == 1) printf("IMPOSSIBLE\n"); else { sort(); for (int i = 0; i < m; i++) { printf("%d\n", ans[i]); } } }
댓글을 작성하려면
로그인
해야 합니다.
gks10101 2년 전
가독성 좋게 정리한 코드입니다... 4프로에서 틀렸다는데 뭐가 문제일까요...