Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 시간 복잡도
- dfs
- 백준 1158
- 조세퍼스 순열
- 자료구조
- Stack 이란
- ㅣ풀이
- 풀이
- 백준 2447
- qorwns
- heap
- 백준 17779
- 게리멘더링2
- 원판 돌리기
- 해시 구현
- AVL 시간 복잡도
- 백준 17471
- c#
- 백준 1406
- 스택의 특징
- 해시구현
- 백준 5397
- 버킷 정렬
- 구현
- 5397
- C/C++ 구현
- 별 찍기 10
- 1764
- 백준 17822
- 백준
Archives
- Today
- Total
홍시홍의 프로그래밍
[백준 10282] 해킹 본문
https://www.acmicpc.net/problem/10282
10282번: 해킹
문제 최흉최악의 해커 yum3이 네트워크 시설의 한 컴퓨터를 해킹했다! 이제 서로에 의존하는 컴퓨터들은 점차 하나둘 전염되기 시작한다. 어떤 컴퓨터 a가 다른 컴퓨터 b에 의존한다면, b가 감염되면 그로부터 일정 시간 뒤 a도 감염되고 만다. 이때 b가 a를 의존하지 않는다면, a가 감염되더라도 b는 안전하다. 최흉최악의 해커 yum3이 해킹한 컴퓨터 번호와 각 의존성이 주어질 때, 해킹당한 컴퓨터까지 포함하여 총 몇 대의 컴퓨터가 감염되며 그에 걸리는
www.acmicpc.net
요구사항
1. 연결에 완료되는 시간 구하기
2. 연결된 컴퓨터 수 구하기
풀이
다익스트라로 풀이한다.
1. 첫 방문일때 cnt++
2. 제일 긴 시간 구하기
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
using namespace std;
struct go {
int x;
int z;
};
int n, d, s;
int dist[10010];
int visit[10010];
int main() {
int t;
scanf("%d", &t);
for (int tc = 1; tc <= t; tc++) {
vector<go> v[10010];
int anscnt = 1;
priority_queue < pair<int, int>, vector<pair<int, int>>, greater<pair<int,int>> > q;
scanf("%d%d%d", &n, &d, &s);
for (int i = 1; i <= n; i++) {
dist[i] = 987654321;
visit[i] = 0;
}
for (int i = 0; i < d; i++) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
v[y].push_back({ x,z });
}
q.push({ 0, s });
dist[s] = 0;
visit[s] = 1;
while (!q.empty()) {
//cout << "A" << endl;
int nowdist = q.top().first;
int nownode = q.top().second;
q.pop();
for (int i = 0; i < v[nownode].size(); i++) {
int nextnode = v[nownode].at(i).x;
int nextvalue = nowdist + v[nownode].at(i).z;
// cout << "N" << nextvalue << endl;
if (dist[v[nownode].at(i).x] > nextvalue) {
if (visit[v[nownode].at(i).x] ==0) anscnt++;
visit[nextnode] = 1;
//cout << "B" << endl;
dist[v[nownode].at(i).x] = nextvalue;
q.push({ nextvalue,nextnode });
}
}
}
int anstime = 0;
for (int i = 1; i <= n; i++) {
if (dist[i] >anstime && dist[i] != 987654321) {
anstime = dist[i];
}
}
printf("%d %d\n", anscnt, anstime);
}
}
'알고리즘 문제풀이 > 백준' 카테고리의 다른 글
[백준 2617] 구슬 찾기 (0) | 2020.03.05 |
---|---|
[백준 3184] 양 (0) | 2020.03.05 |
[백준 2983] 개구리 공주 (0) | 2020.03.04 |
[백준 6118] 숨바꼭질 (0) | 2020.03.04 |
[백준 1620] 나는야 포켓몬 마스터 (0) | 2020.03.02 |
Comments