public DTWResult calculateDistance(long[][] s, long[][] t) {
        int n = s.length;
        int m = t.length;

        double[][] dtw = new double[n][m];

        for (int i = 1; i < n; i++) {
            dtw[i][0] = n;
        }
        for (int i = 1; i < m; i++) {
            dtw[0][i] = m;
        }
        dtw[0][0] = 1;

        for (int i = 1; i < n; i++) {
            double cost = 0;
            for (int j = 1; j < m; j++) {
                cost = calculateEuclidean(s[i],t[j]);
                dtw[i][j] = cost
                        + min(dtw[i - 1][j], dtw[i][j - 1],
                                dtw[i - 1][j - 1]);
            }
        }
        
        DTWResult result = new DTWResult();
        result.setValues(dtw);
        
        int i = n - 1;
        int j = m - 1;
        
        double[][] path = new double[n][m];
        
        while(i>1 && j>1){
        	int minI = i;
        	int minJ = j;
        	
//        	if(i == 0){
//        		minI = 0;
//        		if(dtw[0][j] < dtw[0][j-1]){
//        			minJ = j;
//        		} else {
//        			minJ = j-1;
//        		}
//        	} else if(j == 0){
//        		minJ = 0;
//        		if(dtw[i][0] < dtw[i-1][0]){
//        			minI = i;
//        		} else {
//        			minI = i-1;
//        		}
//        	} else {
        		if(dtw[i - 1][j] < dtw[i - 1][j - 1]){
            		if(dtw[i][j - 1] < dtw[i - 1][j]){
            			minI = i;
            			minJ = j-1;
            		} else {
            			minI = i-1;
            			minJ = j;
            		}
            	} else {
            		if(dtw[i-1][j-1] < dtw[i][j-1]){
            			minI = i-1;
            			minJ = j-1;
            		} else {
            			minI = i;
            			minJ = j-1;
            		}
            	}
        	//}
        	
        	i=minI;
        	j=minJ;
        	
        	path[minI][minJ] = (double)PATH_PIXEL_VALUE;
        	
        }
        
        path[n-1][m-1] = (double)PATH_PIXEL_VALUE;
        
        result.setMinPath(path);
        
        result.setScore(dtw[n-1][m-1]/(n+m));
        
        return result;
    }