#include <stdio.h> #include <iostream> #include <vector> #include <queue> #include <map> #include <math.h> #include <string> #include <string.h> #include <stdlib.h> using namespace std; int N; vector<pair<int, int>> graph[10010]; int visited[10010]; int Max; void BFS(int start) { queue<int> q; q.push(start); visited[start] = 0; while(!q.empty()) { start = q.front(); q.pop(); for(int i = 0; i < graph[start].size(); i++) { if(visited[graph[start][i].first] == -1) { visited[graph[start][i].first] = visited[start] + graph[start][i].second; q.push(graph[start][i].first); if(Max < visited[graph[start][i].first]) { Max = visited[graph[start][i].first]; } } } } } int main(void) { // freopen("B1967_input.txt", "r", stdin); cin >> N; int from, to, weight; while(cin >> from >> to >> weight) { graph[from].push_back({to, weight}); graph[to].push_back({from, weight}); } for(int i = 1; i <= N; i++) { memset(visited, -1, sizeof(visited)); BFS(i); } cout << Max; return 0; } | cs |
'Baekjoon > BFS' 카테고리의 다른 글
[백준 1261] 알고스팟 (BFS) (C/C++) (★★) (0) | 2020.02.16 |
---|---|
[백준 1167] 트리의 지름 (BFS, Tree) (C/C++) (★) (0) | 2020.02.16 |
[백준 2146] 다리 만들기 (BFS) (C/C++) (0) | 2020.01.28 |
[백준 2178] 미로 탐색 (BFS) (C/C++) (0) | 2020.01.28 |
[백준 7576] 토마토 (BFS) (C/C++) (0) | 2020.01.26 |