Detalii evaluare #28880051

Rezumat problemă

#590 Prim

Se dă un graf neorientat ponderat conex cu n vârfuri și m muchii – în care fiecare muchie are asociat un cost, număr natural strict pozitiv. Folosind algoritmul lui Prim, determinați un arbore parțial de cost minim, cu rădăcina în vârful 1.

Detalii

Problema Prim Operații I/O prim.in/prim.out
Limita timp 0.1 secunde Limita memorie Total: 64 MB / Stivă 8 MB
Id soluție #28880051 Utilizator cristea eleonora (eleonoracristea)
Fișier prim.cpp Dimensiune 951 B
Data încărcării 22 Martie 2021, 13:31 Scor / rezultat Eroare de compilare

Evaluare


Mesaj compilare

prim.cpp:1:19: error: stray '#' in program
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                   ^
prim.cpp:1:37: error: stray '#' in program
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                     ^
prim.cpp:1:1: error: 'include' does not name a type
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
 ^
prim.cpp:1:75: error: 'ifstream' does not name a type
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                           ^
prim.cpp:1:100: error: 'ofstream' does not name a type
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                    ^
prim.cpp:1:127: error: 'vector' does not name a type
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                               ^
prim.cpp:1:187: error: 'vector' does not name a type
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                           ^
prim.cpp:1:206: error: 'vector' does not name a type
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                              ^
prim.cpp: In function 'int main()':
prim.cpp:1:238: error: 'cin' was not declared in this scope
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                                                              ^
prim.cpp:1:285: error: 'G' was not declared in this scope
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                                                                                                             ^
prim.cpp:1:337: error: 'priority_queue' was not declared in this scope
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                                                                                                                                                                 ^
prim.cpp:1:354: error: 'pair' was not declared in this scope
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                                                                                                                                                                                  ^
prim.cpp:1:359: error: expected primary-expression before 'int'
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                                                                                                                                                                                       ^
prim.cpp:1:359: error: expected ';' before 'int'
prim.cpp:1:427: error: 'V' was not declared in this scope
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                                                                                                                                                                                                                                                           ^
prim.cpp:1:452: error: 'T' was not declared in this scope
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                    ^
prim.cpp:1:474: error: 'D' was not declared in this scope
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ^
prim.cpp:1:550: error: 'G' was not declared in this scope
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ^
prim.cpp:1:598: error: 'Q' was not declared in this scope
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ^
prim.cpp:1:647: error: expected primary-expression before 'int'
 include <fstream> #include <vector> #include <queue> using namespace std; ifstream cin("prim.in"); ofstream cout("prim.out"); vector <pair<int , int>> G[101]; int n , m , x , y , c , S; vector<int> T , D; vector<bool>V; int main() { for(cin >> n >> m ; m ; --m) { cin >> x >> y >> c; G[x].push_back({c , y}); G[y].push_back({c , x}); } priority_queue < pair<int , int> , vector<pair<int , int>> , greater<pair<int , int>> >Q; V.resize(n + 1 , false); T.resize(n + 1 , -1); D.resize(n + 1 , 0x3f3f3f3f); V[1] = true; T[1] = 0; D[1] = 0; for(auto x : G[1]) { T[x.second] = 1; D[x.second] = x.first; Q.push(x); } for(int k = 1 ; k < n ; k++) { pair<int , int> P; do{ P = Q.top(); Q.pop(); }while(V[P.second]); V[P.second] = true; S += P.first; for(auto x : G[P.second]) if(V[x.second] == false && D[x.second] > x.first) { T[x.second] = P.second; D[x.second] = x.first; Q.push(x); } } cout << S << '\n'; for(int i = 1 ;i <= n ; i++) cout << T[i] << " "; }
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ^
prim.cpp:1:647: error: expected ';' before 'int'

cc1plus: out of memory allocating 1677721600 bytes after a total of 466944 bytes

Cum funcționează evaluarea?

www.pbinfo.ro permite evaluarea a două tipuri de probleme:

  • probleme la care rezolvarea presupune scrierea unui program complet
  • probleme la care rezolvarea presupune scrierea unei secvențe de program - câteva instrucțiuni, o listă de declarații, una sau mai multe funcții, etc.

Problema Prim face parte din prima categorie. Soluția propusă de tine va fi evaluată astfel:

  • Programul sursă este compilat folosind compilatorul corespunzător. Dacă în urma compilării se obțin erori sau avertismente, acestea sunt afișate în această pagină.
  • Dacă programul a fost compilat, executabilul obținut va fi rulat, furnizându-i-se unul sau mai multe seturi de date de intrare, în concordanță cu restricțiile specifice problemei. Pentru fiecare set de date se obține un anumit punctaj, în raport cu corectitudinea soluției tale.

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ă.