07-02 03:43
벤치마킹
Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 양양솔비치세프스키친
- 양양솔비치 뷔페
- 편도수술
- 주차넉넉
- DFS
- 커피
- 사진문자추출하기
- 고마워다음
- 가족소고기외식
- 결항전문
- 당근마켓중고차
- 검색완료
- 푸르지오포레피스
- 커피쏟음
- 싱가폴중학교수학문제
- 홍시스무디
- 영통역소고기
- 양양솔비치조식
- 아이혼자다녀옴
- 결항
- 파이썬
- 영통칠프로칠백식당
- 종이캐리어
- 오트눈썰매장
- 에어아시아
- 사진에서 글자추출
- 사진문자추출
- 양양솔비치아침
- 중학교입학수학문제
- 영통외식
Archives
- Today
- Total
너와나의 관심사
백준 1707문제 본문
그래프 연결 문제로 linked list 로 인접 행렬을 구현해서.. 연습용 문제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | #include <stdio.h> #include <iostream> #include <vector> #include <cmath> #include <string> #include <set> #include <queue> #include <functional> #include <algorithm> #include <memory.h> #pragma warning(disable : 4996) using namespace std; long long min_v, max_v; #define MAX(a,b) a>b ? a:b #define MIN(a,b) a>b ? b:a int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 }; int N; vector<vector<int> > adj; // 인접리스트 //vector<int>color; // 인접리스트 short color[20002]; // 0은 아직 방문 X, -1 또는 1은 방문한 정점의 색 typedef struct _arr{ int data; struct _arr *next; struct _arr *prev; }Arr; Arr *Graph[20001] = { 0, }; Arr temp_buf[2000001] = { 0, }; int NumCnt = -1; int ac [20001] = { 0, }; void Init(){ NumCnt = -1; memset(color, 0, sizeof (color)); memset(Graph, 0, sizeof (Graph)); memset(temp_buf, 0, sizeof (temp_buf)); memset(ac, 0, sizeof (ac)); } Arr * getListNode(void ) { NumCnt++; temp_buf[NumCnt].data = 0; temp_buf[NumCnt].next = &temp_buf[NumCnt]; temp_buf[NumCnt].prev = &temp_buf[NumCnt]; return &temp_buf[NumCnt]; } Arr * appendListNode(Arr* list, int data) { Arr * node = getListNode(); node->data = data; if (list == NULL) { return node; } else { Arr* last = list->prev; last->next = node; list->prev = node; node->prev = last; node->next = list; return list; } } void Edge(int start, int end){ Graph[start] = appendListNode(Graph[start], end); ac[start]++; } // @ret : false , true; // @int n : number of idx // @int c : color 1 or 1 , 0 --> 방문안한곳 bool DFS(int n, int c) { color[n] = c; Arr *temp = Graph[n]; int cnt = 0; while (temp && cnt < ac[n]){ int next = temp->data; if (color[next] != 0 && color[next] == c) return false; if (color[next] == 0 ) { if (!DFS(next, c * -1)) return false; } temp = temp->next; cnt++; } return true; } // size , @ret => non chk idx int chk_c(int adj_size){ for (int i = 0; i < adj_size; i++) if (color[i] == 0) return i; //all done return -1; } int main() { int TC = 1; int V, E; bool ans = true; int a, b; //freopen("input.txt", "r", stdin); setbuf(stdout, NULL); cin >> TC; while (TC--){ ans = true; cin >> V >> E; Init(); // 인접리스트 저장 for (int i = 0; i < E; i++) { cin >> a >> b; Edge(a, b); Edge(b, a); } for (int i = 0; i < V; i++) { if (color[i] == 0) { if (!DFS(i, 1)) { ans = false; break; } } } if (ans) cout << "YES" << endl; else cout << "NO" << endl; } return 0; } | cs |
Comments