-
Notifications
You must be signed in to change notification settings - Fork 4
[220323] BOJ_DFS_BFS_효율적인 해킹 #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
GnuPark/PS/BOJ/DFS_BFS/효율적인_해킹_1325.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package BOJ.DFS_BFS; | ||
|
||
import java.io.*; | ||
import java.util.*; | ||
|
||
public class 효율적인_해킹_1325 { | ||
static int n, m; | ||
static int ans; | ||
static boolean visit[]; | ||
static int arr[]; | ||
static ArrayList<Integer>[] graph; | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
n = Integer.parseInt(st.nextToken()); | ||
m = Integer.parseInt(st.nextToken()); | ||
graph = new ArrayList[n+1]; | ||
arr = new int[n+1]; | ||
for (int i = 1; i <= n; i++) { | ||
graph[i] = new ArrayList<>(); | ||
} | ||
|
||
for (int i = 0; i < m; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
int s = Integer.parseInt(st.nextToken()); | ||
int e = Integer.parseInt(st.nextToken()); | ||
|
||
graph[e].add(s); | ||
} | ||
|
||
for (int i = 1; i <= n; i++) { | ||
visit = new boolean[n + 1]; | ||
bfs(i); | ||
} | ||
StringBuffer sb = new StringBuffer(); | ||
for (int i = 1; i < arr.length; i++) { | ||
if (arr[i] == ans){ | ||
sb.append(i + " "); | ||
} | ||
} | ||
System.out.println(sb.toString()); | ||
|
||
} | ||
|
||
public static void bfs(int index){ | ||
Queue<Integer> q = new LinkedList<Integer>(); | ||
q.offer(index); | ||
visit[index] = true; | ||
|
||
while (!q.isEmpty()) { | ||
int now = q.poll(); | ||
|
||
for (int v : graph[now]){ | ||
if(!visit[v]) { | ||
visit[v] = true; | ||
arr[index] ++; | ||
q.offer(v); | ||
} | ||
} | ||
} | ||
if (ans < arr[index]){ | ||
ans = arr[index]; | ||
} | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.