회원가입
로그인
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
문제집
대회
2
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
테스트케이스가 부족한 건가요? 운인가요?
9470번 - Strahler 순서
chhi0123
6년 전
0
나머지 노드는 그 노드로 들어오는 강의 순서 중 가장 큰 값을 i라고 했을 때, 들어오는 모든 강 중에서 Strahler 순서가 i인 강이 1개이면 순서는 i, 2개 이상이면 순서는 i+1이다.
이 규칙을 잘못 이해해서 푼게
https://www.acmicpc.net/source/7830012
인데요, 48번째 줄을 보시면 들어오는 강의 순서 중 가장 큰 값(i)에, i의 갯수를 다 더해버리고 1을 뺏습니다.
그러니까 어떤 노드에 들어오는 강의 순서가 {3, 3, 3}이라면 원래는 순서가 4가 되어야 하는데, 제 풀이로는 5가 되는 거죠.
이걸 깨닫고 고친게
https://www.acmicpc.net/source/7830415
입니다. 107번째 줄 부터 보시면 카운트를 1인지, 1보다 큰지를 나눠서 강의 순서를 정해줬습니다.
둘 다 맞은게 운인지 {3, 3, 3}같은 경우가 테스트케이스에 없었던 건지 궁금하네요.
#include <stdio.h> #include <vector> #include <queue> using namespace std; struct Strahler { int max, order_cnt[1001], order; }; int in[1001]; int k, kk, m, p, a, b; int main() { scanf("%d", &k); while (k--) { scanf("%d %d %d", &kk, &m, &p); for (int i = 1; i <= m; ++i) in[i] = 0; vector<vector<int>> vec(m + 1); for (int i = 0; i < p; ++i) { scanf("%d %d", &a, &b); vec[a].push_back(b); in[b]++; } vector<Strahler> st(m + 1); queue<int> q; for (int i = 1; i <= m; ++i) { if (!in[i]) { q.push(i); st[i].order = 1; } } while (!q.empty()) { int cur = q.front(); q.pop(); for (auto next : vec[cur]) { if (st[next].max < st[cur].order) st[next].max = st[cur].order; st[next].order_cnt[st[cur].order]++; in[next]--; if (!in[next]) { st[next].order = st[next].max + st[next].order_cnt[st[next].max] - 1; q.push(next); } } } printf("%d %d\n", kk, st[m].order); } return 0; } ///////////////////////////////////////////////////////////////////////////////////////////// #include <stdio.h> #include <vector> #include <queue> using namespace std; struct Strahler { int max, order_cnt[1001], order; }; int in[1001]; int k, kk, m, p, a, b; int main() { scanf("%d", &k); while (k--) { scanf("%d %d %d", &kk, &m, &p); for (int i = 1; i <= m; ++i) in[i] = 0; vector<vector<int>> vec(m + 1); for (int i = 0; i < p; ++i) { scanf("%d %d", &a, &b); vec[a].push_back(b); in[b]++; } vector<Strahler> st(m + 1); queue<int> q; for (int i = 1; i <= m; ++i) { if (!in[i]) { q.push(i); st[i].order = 1; } } while (!q.empty()) { int cur = q.front(); q.pop(); for (auto next : vec[cur]) { if (st[next].max < st[cur].order) st[next].max = st[cur].order; st[next].order_cnt[st[cur].order]++; in[next]--; if (!in[next]) { if (st[next].order_cnt[st[next].max] == 1) st[next].order = st[next].max; else if (st[next].order_cnt[st[next].max] > 1) st[next].order = st[next].max + 1; q.push(next); } } } printf("%d %d\n", kk, st[m].order); } return 0; }
댓글을 작성하려면
로그인
해야 합니다.
chhi0123 6년 전