soumiaMoufid's blog

By soumiaMoufid, history, 8 years ago, In English

please i got "runtime error on test 11" with this code any help?? thanks in advance



import java.io.PrintWriter; import java.util.Scanner; public class GregAndGraph { int [][]graph;//pour stocker la matrice de graphe int []noeudSupp;//pour les noeuds supprimer int []somme;//somme de plus court chemin int [][] data; public GregAndGraph() { //saisie Scanner in = new Scanner(System.in); PrintWriter out=new PrintWriter (System.out); int n=in.nextInt(); graph=new int[n+1][n+1]; data=new int[n+1][n+1]; noeudSupp=new int[n+1]; somme=new int[n+1]; int []id=new int[30]; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ graph[i][j]=in.nextInt(); data[i][j]=graph[i][j]; } } for(int i=1;i<=n;i++){ noeudSupp[i]=in.nextInt(); id[noeudSupp[i]]=i; somme[i]=0; } for (int k = 1; k <= n; k++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { graph[i][j] = Math.min(graph[i][j], graph[i][noeudSupp[n-k+1]] + graph[noeudSupp[n-k+1]][j]); if (id[i] > n-k && id[j] > n-k) somme[k] += graph[i][j]; } } } for (int k = n; k >= 1; k--) { System.out.print(somme[k] + " "); } } public static void main(String[] args) { new GregAndGraph(); } }

Full text and comments »

  • Vote: I like it
  • -23
  • Vote: I do not like it

By soumiaMoufid, history, 8 years ago, In English

please i got "rutime error on test 1" with this code any help?? thanks in advance

package graph.party;

import java.util.ArrayList;
import java.util.Scanner;

public class Party2 {

	public Party2() {
		Scanner in = new Scanner(System.in);
		System.out.println("entrez le nombre des employés\n");
		int n = in.nextInt();
		ArrayList<Integer> tab=new ArrayList<Integer>(n);
		for(int i=0;i<n;i++){
			tab.add(in.nextInt());
		}
		int result=0;
		for(int j=0;j<n;j++){
			int temp=1;int var=tab.get(j);
			while(var != -1){var=tab.get(var-1);temp++;}
			if(temp>result) result=temp;
		}
		System.out.println(result);
	}

	public static void main(String[] args) {
		new Party2();

	}

}

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it