Cześć!
Robię takie zadanko https://codeforces.com/contest/1572/problem/A
i taki kod do niego:
#include <bits/stdc++.h>
using namespace std;
int read = 0;
void dfs(int v, vector<vector<int>>& graph, vector<int>& need, vector<bool>& seen, set<int>& que_now){
seen[v] = true;
read++;
for (auto& child : graph[v]){
need[child]--;
if (need[child] == 0 && child > v && seen[child] == false)
dfs(child, graph, need, seen, que_now);
else if (need[child] == 0 && seen[child] == false && child < v)
que_now.insert(child);
}
}
void solve(){
int n;
cin >> n;
vector<vector<int>> graph(n+1);
vector<int> need(n+1);
vector<bool> seen(n+1);
set<int> que, que_now;
for (int i = 1; i <= n; i++){
int num;
cin >> need[i];
for (int j = 0; j < need[i]; j++){
cin >> num;
graph[num].push_back(i);
}
}
for (int i = 1; i <= n; i++)
if (need[i] == 0 && seen[i] == false)
que.insert(i);
read = 0;
int times = 0;
while (que.size()){
for (auto& v : que){
if (seen[v] == false)
dfs(v, graph, need, seen, que_now);
}
que = que_now;
que_now.clear();
times++;
}
if (read != n){
cout << -1 << '\n';
return;
}
cout << times << '\n';
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t;
cin >> t;
while (t){
solve();
t--;
}
return 0;
}
Gdy kompiluje go u siebie wszystko działa tak jak powinno, gdy wysyłam program do sprawdzenia dostaje Runtime error i Exit code is 2147483647. Odpaliłem address sanitizer
wojtek@Linux:~/project$ ./lol
ASAN:DEADLYSIGNAL
=================================================================
==5719==ERROR: AddressSanitizer: SEGV on unknown address 0x56241fca4380 (pc 0x56241fca4380 bp 0x000000001fff sp 0x7fffc1608948 T0)
==5719==The signal is caused by a READ memory access.
#0 0x56241fca437f (/home/wojtek/project/lol+0x20937f)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/home/wojtek/project/lol+0x20937f)
==5719==ABORTING
po samej próbie odpalenia programu jest jakiś błąd. Dlaczego?