Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 2 KB
package hu.krivan.szakkor.varos;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.HashSet;
@author
public class Varosok {
private int n, m;
private int[] counties;
private HashSet<Integer>[] neighbours;
public Varosok() throws FileNotFoundException, IOException
{
BufferedReader in = new BufferedReader(new FileReader("varos.be"));
PrintWriter out = new PrintWriter(new FileWriter("varos.ki"));
String[] lines;
String input;
while( (input = in.readLine()) != null )
{
n = Integer.valueOf(input.split(" ")[0]);
m = Integer.valueOf(input.split(" ")[1]);
lines = new String[m];
counties = new int[ n ];
neighbours = new HashSet[ n ];
for( int i=0; i<lines.length; i++ ) {
lines[i] = in.readLine();
int a = Integer.valueOf(lines[i].split(" ")[0])-1;
int b = Integer.valueOf(lines[i].split(" ")[1])-1;
int c = Integer.valueOf(lines[i].split(" ")[2])-1;
if( neighbours[a] == null ) {
neighbours[a] = new HashSet<Integer>();
}
if( neighbours[b] == null ) {
neighbours[b] = new HashSet<Integer>();
}
if( neighbours[c] == null ) {
neighbours[c] = new HashSet<Integer>();
}
neighbours[a].add(b);
neighbours[a].add(c);
neighbours[b].add(a);
neighbours[b].add(c);
neighbours[c].add(a);
neighbours[c].add(b);
counties[a]++;
counties[b]++;
counties[c]++;
}
}
int hatar = 0;
StringBuffer sb = new StringBuffer();
for( int i=0; i<n; i++ ) {
if( neighbours[i].size() != counties[i] ) {
hatar++;
}
if( i != 0 ) sb.append( " " );
sb.append( neighbours[i].size() );
}
out.println( hatar );
out.println( sb.toString() );
out.close();
}
@param
public static void main(String[] args) throws FileNotFoundException, IOException {
new Varosok();
}
}