#1861
Se dă un graf orientat aciclic cu N noduri numerotate de la 1 la N. Să se realizeze o sortare topologică a nodurilor.
| Problema | TopSort | Operații I/O |
topsort.in/topsort.out
|
|---|---|---|---|
| Limita timp | 0.5 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
| Id soluție | #64686675 | Utilizator | |
| Fișier | topsort.cpp | Dimensiune | 1.00 KB |
| Data încărcării | 22 Mai 2026, 21:37 | Scor/rezultat | Eroare de compilare |
topsort.cpp:5:1: error: ‘ifstream’ does not name a type 5 | ifstream in("topsort.in"); | ^~~~~~~~ topsort.cpp:6:1: error: ‘ofstream’ does not name a type 6 | ofstream out("topsort.out"); | ^~~~~~~~ topsort.cpp: In function ‘int main()’: topsort.cpp:11:5: error: ‘in’ was not declared in this scope; did you mean ‘n’? 11 | in >> n >> m; | ^~ | n topsort.cpp:13:5: error: ‘vector’ was not declared in this scope; did you mean ‘std::vector’? 13 | vector<vector<int>> adj(n + 1); | ^~~~~~ | std::vector In file included from /usr/include/c++/13/vector:66, from topsort.cpp:2: /usr/include/c++/13/bits/stl_vector.h:428:11: note: ‘std::vector’ declared here 428 | class vector : protected _Vector_base<_Tp, _Alloc> | ^~~~~~ topsort.cpp:13:19: error: expected primary-expression before ‘int’ 13 | vector<vector<int>> adj(n + 1); | ^~~ topsort.cpp:14:12: error: expected primary-expression before ‘int’ 14 | vector<int> in_degree(n + 1); | ^~~ topsort.cpp:17:9: error: ‘adj’ was not declared in this scope 17 | adj[x].push_back(y); | ^~~ topsort.cpp:18:9: error: ‘in_degree’ was not declared in this scope 18 | in_degree[y]++; | ^~~~~~~~~ topsort.cpp:21:5: error: ‘queue’ was not declared in this scope; did you mean ‘std::queue’? 21 | queue<int> q; | ^~~~~ | std::queue In file included from /usr/include/c++/13/queue:66, from topsort.cpp:3: /usr/include/c++/13/bits/stl_queue.h:96:11: note: ‘std::queue’ declared here 96 | class queue | ^~~~~ topsort.cpp:21:11: error: expected primary-expression before ‘int’ 21 | queue<int> q; | ^~~ topsort.cpp:23:13: error: ‘in_degree’ was not declared in this scope 23 | if (in_degree[i] == 0) { | ^~~~~~~~~ topsort.cpp:24:13: error: ‘q’ was not declared in this scope 24 | q.push(i); | ^ topsort.cpp:28:12: error: expected primary-expression before ‘int’ 28 | vector<int> topsort; | ^~~ topsort.cpp:29:13: error: ‘q’ was not declared in this scope 29 | while (!q.empty()) { | ^ topsort.cpp:32:9: error: ‘topsort’ was not declared in this scope; did you mean ‘qsort’? 32 | topsort.push_back(node); | ^~~~~~~ | qsort topsort.cpp:34:29: error: ‘adj’ was not declared in this scope 34 | for (int i = 0; i < adj[node].size(); i++) { | ^~~ topsort.cpp:36:13: error: ‘in_degree’ was not declared in this scope 36 | in_degree[neigh]--; | ^~~~~~~~~ topsort.cpp:43:15: error: ‘topsort’ was not declared in this scope; did you mean ‘qsort’? 43 | int len = topsort.size(); | ^~~~~~~ | qsort topsort.cpp:45:9: error: ‘out’ was not declared in this scope 45 | out << topsort[i] << " "; | ^~~
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema TopSort face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:
Suma punctajelor acordate pe testele utilizate pentru verificare este 100. Astfel, soluția ta poate obține cel mult 100 de puncte, caz în care se poate considera corectă.