Выдает ошибку при решение задачи
входные данные
3 1
1 2
1 3
0
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> arr;
vector<bool> used;
void dfs(int v) {
used[v] = true;
for (auto to : arr[v]) {
if (!used[to]) {
dfs(to);
}
}
}
int main() {
int n, k;
cin >> n >> k;
int z, t;
arr.resize(n);
while (true) {
cin >> z;
if (z == 0) {
break;
}
cin >> t;
arr[z - 1].push_back(t - 1);
}
dfs(k - 1);
for (auto i : used) {
if (!i) {
cout << "No";
return 0;
}
}
cout << "Yes";
return 0;
}
задан 8 янв 2020 в 18:51
1
SIGSEGV — Это ошибка по защите памяти. Т.е. ваша программв пытается обратиться к участку памяти, который ей не принадлежит. В 99% процентах случаев, такая ошибка возникает по двум причинам:
- Индекс массива выходит за допустимый диапазон
- Указатель получает некое «левое» (или вообще — никакого) значение.
У вас указателей нет, но есть два массива (вектора) с индексами которых далеко не всё очевидно.
Разбираться с ними глядя на код — скучно. Поэтому рекомендую скомпилировать Вашу программу с ключом -g и запустить под отладчиком gdb. Он Вам покажет конкретное место ошибки.
ответ дан 9 янв 2020 в 4:47
SergeySergey
12.9k12 серебряных знаков26 бронзовых знаков
- Forum
- General C++ Programming
- Error Code 139
Error Code 139
Hello, I am implementing a Hash Table based on a given function. I have coded most of it, but whenever I try to add something to the hash table, I get an error code of 139. I’ve narrowed it down to where it crashes (HashTab.cpp in the add() function), and I would appreciate if someone looked over my code and offered suggestions or a solution to make it not crash anymore. Here is the code:
|
|
|
|
|
|
|
|
|
|
Please let me know what I am doing wrong.
«Error 16» is meaningless. Error numbers are different for every compiler.
You also don;t make clear if this is a compiler error, or a run time error.
Please post the full error text of the message including the source filename and line number where the error occurred.
Sorry! It’s a run time error. The program itself executes fine. Here is the output when I try to use the add() function.
|
|
HashTab* hashTab;
This defines a pointer to a
HashTab
. Later you dereference the pointer without ever making it point to anything valid.
|
|
This defines an array of pointers to
Element
in each HashTab instance. Later you use this array without making those pointers point to anything valid.
So just do something like this?
HashTab* hashTab = new HashTab():
and
Element* elarray = new Element[7];
Pointers are still very new to me, and I was under the impression that
HasTab* hashTab
would declare and create a valid pointer to use.
So just do something like this?
HashTab* hashTab = new HashTab();
Something like it.
and
Element* elarray = new Element[7];
elarray
as defined in the code above is an array of 7 pointers-to-
Element
. You could change the definition to something like described here, or you could keep it as you previously had it and make those pointers point to objects, or you could just use a normal array of 7
Element
objects.
Pointers are still very new to me, and I was under the impression that
HasTab* hashTab
would declare and create a valid pointer to use.
It defines a pointer. Given that it is defined at global scope, it is zero-initialized. It is not valid to dereference as it does not point to an existing object.
The thing to remember about pointers is that you shouldn’t use them unless you can’t get around it.
Last edited on
Cool. I kept the HashTab as a pointer and made my Element array out of objects instead. Works like a charm, thank you cire and AbstractionAnon!
Topic archived. No new replies allowed.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Closed
hez2010 opened this issue
Apr 30, 2018
· 14 comments
Closed
error MSB6006: «csc.dll» exited with code 139
#26505
hez2010 opened this issue
Apr 30, 2018
· 14 comments
Assignees
Comments
Version Used:
the version embedded in the dotnet SDK version 2.2.100-preview1-008633 (daily build)
Steps to Reproduce:
- edit nuget.config file:
- navigate to any folder u like and using «dotnet new console» to create a .net core 2.1 console application
- dotnet build
note: my system is ubuntu 16.04 ARM64
Expected Behavior:
successfully build.
Actual Behavior:
…/sdk/2.2.100-preview1-008633/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: «csc.dll» exited with code 139. [/home/nvidia/Desktop/test/test.csproj]
build log:s (with -v diag)
log.txt
@hez2010 Here’s what I’d recommend you try:
Here are some steps to see the reason for the compilation failing:
- run the problematic
build
command, but add the option for binary logging/bl
(for example,dotnet build /bl
) - assuming this reproduced the issue, open the
msbuild.binlog
file with the binary log viewer. - the log viewer should show the failed
Csc
task (as shown below) - you can view and copy the command-line arguments to a text file
repro.rsp
, removing the first two chunks (the first one for «dotnet.exe» and the second one for «csc.dll») - re-use those two chunks to run
dotnet.exe csc.dll @repro.rsp
- this should repro, but also print out the compiler diagnostics
Tagging @livarcocc, in case he has something to add. Livar, are there any known issues where CLI doesn’t print out the compiler diagnostics? I thought there was one, but it had been fixed.
I didn’t hear back on my request for additional information, so I’ll go ahead and close the issue.
The problem of the error details not getting displayed was fixed in the compiler (#27349) and we’ll have to wait for that fix to make its way into the CLI.
If the problem still occurs, please open an issue with more details. Thanks
@jcouv I have the same issue and i did the steps you have wrote above.
The output is:
Microsoft (R) Visual C# Compiler version 2.8.1.62915 (ff873b4b)
Copyright (C) Microsoft Corporation. All rights reserved.
warning CS2023: Ignoring /noconfig option because it was specified in a response file
Segmentation fault (core dumped)
I am running on openSUSE Tumbleweed (JeOS 4.16.6-1-default, aarch64) on a Raspberry PI 3B+. I use .NET Core SDK 2.1.300.
@xclud I will try to find out how to get a stacktrace from a crashed process on Linux.
Is there any chance you could try and repro on windows? (the troubleshooting experience is easier there)
@kxxt Would you be able to share a crash dump of this crash (since you said it was on Windows)? Here are some instructions for turning that one. Then you can share via any online drive. Thanks
@jcouv Actually this issue only occurs on Linux ARM64 system and currently I don’t have the environment to repo it. You can try executing «dotnet build» on Linux ARM64, I think this issue will 100% repo.
Have the same issue. Just installed dotnet sdk 2.1.302 on a fresh Debian 9 arm64. And any try to build a project results in error from this topic
I have the same issue on my Jetson TX2 (arm64 — ubuntu 16.04).
@jcouv I do not face any issues on Windows. I compile for windows on windows and also cross-compile on windows for linux (x64 and arm64). No problem at all.
To me, the problem happens only when i compile on my raspberry pi.
This is likely an ARM64 runtime issue. Tagging @RussKeldorph for that.
I have the same issue on ROCK64 V2 4G RAM. I can build project, run dotnet restore. When I run dotnet run for console application I am getting: /home/rock64/dotnet/sdk/2.1.402/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: «csc.dll» exited with code 139. [/home/rock64/dev/myApp/myApp.csproj]
The build failed. Please fix the build errors and run again.
/opt/dotnet-sdk-2.1.402/sdk/2.1.402/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: "csc.dll" exited with code 139.
Build FAILED.
Ubuntu 16.04 AARCH64
I have the same problem ,my project run on androd Linux Deploy
Welcome to Ubuntu 16.04 LTS (GNU/Linux 4.9.65-perf+ armv8l)
- Documentation: https://help.ubuntu.com/
Ubuntu 16.04 LTS [running via Linux Deploy]
Last login: Thu Oct 4 13:24:51 2018 from 127.0.0.1
root@localhost:~#
build error:
Restore completed in 63.74 ms for /home/android/gitCodes/myGit/OrchardCore/test/OrchardCore.Tests.Pages/OrchardCore.Application.Pages/OrchardCore.Application.Pages.csproj.
/home/dotnet/sdk/2.1.403/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: «csc.dll» exited with code 139. [/home/android/gitCodes/myGit/OrchardCore/src/OrchardCore/OrchardCore.BackgroundTasks.Abstractions/OrchardCore.BackgroundTasks.Abstractions.csproj]
/home/dotnet/sdk/2.1.403/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: «csc.dll» exited with code 139. [/home/android/gitCodes/myGit/OrchardCore/src/OrchardCore/OrchardCore.Data.Abstractions/OrchardCore.Data.Abstractions.csproj]
/home/dotnet/sdk/2.1.403/Roslyn/Microsoft.CSharp.Core.targets(52,5): error MSB6006: «csc.dll» exited with code 139. [/home/android/gitCodes/myGit/OrchardCore/src/OrchardCore/OrchardCore.XmlRpc.Abstractions/OrchardCore.XmlRpc.Abstractions.csproj]
/home/dotnet/sdk/2.1.403/Roslyn/Microsoft.CSharp.Core.targets(52,5): error M