Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Naloga9 {
- public static int [] osebe;
- public static int [][] povezave;
- public static int N;
- public static void main(String[] args) throws FileNotFoundException, IOException {
- BufferedReader bufferedReader = new BufferedReader(new FileReader(args[0]));
- StringBuffer stringBuffer = new StringBuffer();
- String line = null;
- line = bufferedReader.readLine();
- Scanner sc = new Scanner(System.in);
- N = Integer.parseInt(line);
- line = bufferedReader.readLine();
- int M = Integer.parseInt(line);;
- String result = "";
- osebe = new int[N];
- povezave = new int[N][N];
- line = bufferedReader.readLine();
- for (int i = 0; i < M; i++) {
- String v = line;
- String [] vrstica = v.split(",");
- povezave[Integer.parseInt(vrstica[0]) - 1][Integer.parseInt(vrstica[1]) - 1] = 1;
- line = bufferedReader.readLine();
- }
- for (int i = 0; i < N; i++) {
- boolean vsajEden = false;
- for (int j = 0; j < N; j++) {
- boolean poklici = true;
- if (osebe[j] == 1) continue;
- for (int k = 0; k < N; k++) {
- if (osebe[k] != 1) {
- if (povezave[j][k] == 1) {
- poklici = false;
- break;
- }
- }
- }
- if (poklici) {
- vsajEden = true;
- osebe[j] = 1;
- result = result + (j+1) + ",";
- break;
- }
- }
- if(!vsajEden){
- result = "-1";
- break;
- }
- }
- if(!result.equals("-1"))
- result = result.substring(0, result.length() - 1);
- BufferedWriter writer = new BufferedWriter(new FileWriter(args[1], true));
- writer.write(result);
- writer.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement