Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with C# List when compiled in mono (homework-related)

I'll admit this is my homework. The task statement said I have to write a program that finds a topological order of a graph which would be inputted by standard input. Then I need to submit it to be graded on the professor's server.

Now it's not the algorithm problem. It's more of a technical problem. In my computer, I use .NET compiler (csc) while the professor's grading machine uses some form of mono.

It works well, until the grader said I got 30/100. A friend of mine suggested that I use the grader's "manual input system", so here I go, I made it create array-of-100000 lists for the adjacency list.

The grader, after a few seconds, reported that my program has crashed.

Stacktrace:

at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke_object__this__ (object,intptr,intptr,intptr) <0xffffffff>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0x00004>
at (wrapper managed-to-native) object.__icall_wrapper_mono_object_new_fast (intptr) <0xffffffff>
at System.Exception.ToString () <0x00026>
at (wrapper runtime-invoke) object.runtime_invoke

This is kinda strange and unsettling to me, but I have yet to find an answer for this. Again, this program worked really fine on my PC.

This is my part of the program:

using System;
using System.Collections;
using System.Collections.Generic;

class topo{
public static void Main(){
    string[] ST = Console.ReadLine().Split(' ');
    int N=Convert.ToInt32(ST[0]), M=Convert.ToInt32(ST[1]);
    int[] ins = new int[N];  //node's total in-degrees
    List<int>[] E = new List<int>[N];

    for(int n=0;n<N;n++)    
        E[n] = new List<int>();

    for(int m=0;m<M;m++){
        ST = Console.ReadLine().Split(' ');
        int u = Convert.ToInt32(ST[0]);
        int v = Convert.ToInt32(ST[1]);
        E[u-1].Add(v-1);
        ins[v-1]++;
    }

    Queue S = new Queue();
    List<int> L = new List<int>(); //result list

    for(int n=0;n<N;n++){
        //add stranded nodes directly and don't process it
        if(ins[n]==0 && E[n].Count==0)
            L.Add(n);

        //put into queue
        else if(ins[n]==0)
            S.Enqueue(n);
    }

    while(S.Count>0){
        int n = (int) S.Dequeue();
        L.Add(n);
        foreach(int m in E[n])
            if(--ins[m]==0)
                S.Enqueue(m);
    }

    foreach(int n in L)
        Console.WriteLine(n+1);

}

}

Thank you very much, and I appreciate any and every response.

Edit: I took another look at the grader's output to see if I missed anything, and indeed I did. It said "syscal: 2", but all I know about it is that "the program didn't exit normally."

Edit #2: I've tried making the program attempt to make various sizes of the array-of-list, ranging from 5000, 10000, etc. and after 40000 the "manual input system" said the program got a System.OutOfMemoryException. With further look into various parts of the grader that the students are allowed into, it seems that prof misconfigured his grading parameters and gave us less memory than announced. (He said "32MB", but the program crashes at about 16MB)

I've reported the error to him and he is (right now) looking into it.

like image 794
LunaticNeko Avatar asked Mar 12 '11 17:03

LunaticNeko


People also ask

What is problem in C programming?

It is the programmer who has to write down the solution to the problem in terms of simple operations which the computer can understand and execute. Problem-solving is a sequential process of analyzing information related to a given situation and generating appropriate response options.

Is C an obsolete language?

The C programming language doesn't seem to have an expiration date. It's closeness to the hardware, great portability and deterministic usage of resources makes it ideal for low level development for such things as operating system kernels and embedded software.


1 Answers

The following code is going to fail if the value of u or v is less than 1.

for(int m=0;m<M;m++){
    ST = Console.ReadLine().Split(' ');
    int u = Convert.ToInt32(ST[0]);
    int v = Convert.ToInt32(ST[1]);
    E[u-1].Add(v-1);
    ins[v-1]++;
}

Because u-1 or v-1 is going to be negative, and that will throw an exception.

like image 175
Jim Mischel Avatar answered Nov 03 '22 05:11

Jim Mischel