#2888
Se consideră un graf neorientat conex cu n
noduri și n
muchii. Să se determine numărul arborilor parțiali ai grafului.
Problema | Spanning Tree | Operații I/O |
![]() |
---|---|---|---|
Limita timp | 0.3 secunde | Limita memorie |
Total: 64 MB
/
Stivă 8 MB
|
Id soluție | #57396370 | Utilizator | |
Fișier | spanning_tree.cpp | Dimensiune | 579 B |
Data încărcării | 29 Martie 2025, 07:06 | Scor / rezultat | Eroare de compilare |
spanning_tree.cpp:4:26: error: size of array 'A' is too large int n; int A[30005][30005]; bool v[30005]; int d[30005]; int c=0; bool f=false; void dfs(int x, int p) { v[x]=true; for (int y=1; y<=n; y++) { if (A[x][y]) { if (y==p) continue; if (!v[y]) { d[y]=d[x]+1; dfs(y,x); } else if (!f) { c = d[x]-d[y]+1; f = true; } } } } int main() { cin >> n; for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++) { A[i][j]=0; } v[i]=false; d[i]=0; } for (int i=1; i<=n; i++) { int x, y; cin >> x >> y; A[x][y] = A[y][x] = 1; } d[1]=1; dfs(1,0); cout << c; return 0; } ^ spanning_tree.cpp: In function 'void dfs(int, int)': spanning_tree.cpp:4:148: error: 'A' was not declared in this scope int n; int A[30005][30005]; bool v[30005]; int d[30005]; int c=0; bool f=false; void dfs(int x, int p) { v[x]=true; for (int y=1; y<=n; y++) { if (A[x][y]) { if (y==p) continue; if (!v[y]) { d[y]=d[x]+1; dfs(y,x); } else if (!f) { c = d[x]-d[y]+1; f = true; } } } } int main() { cin >> n; for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++) { A[i][j]=0; } v[i]=false; d[i]=0; } for (int i=1; i<=n; i++) { int x, y; cin >> x >> y; A[x][y] = A[y][x] = 1; } d[1]=1; dfs(1,0); cout << c; return 0; } ^ spanning_tree.cpp: In function 'int main()': spanning_tree.cpp:4:344: error: 'A' was not declared in this scope int n; int A[30005][30005]; bool v[30005]; int d[30005]; int c=0; bool f=false; void dfs(int x, int p) { v[x]=true; for (int y=1; y<=n; y++) { if (A[x][y]) { if (y==p) continue; if (!v[y]) { d[y]=d[x]+1; dfs(y,x); } else if (!f) { c = d[x]-d[y]+1; f = true; } } } } int main() { cin >> n; for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++) { A[i][j]=0; } v[i]=false; d[i]=0; } for (int i=1; i<=n; i++) { int x, y; cin >> x >> y; A[x][y] = A[y][x] = 1; } d[1]=1; dfs(1,0); cout << c; return 0; } ^ spanning_tree.cpp:4:431: error: 'A' was not declared in this scope int n; int A[30005][30005]; bool v[30005]; int d[30005]; int c=0; bool f=false; void dfs(int x, int p) { v[x]=true; for (int y=1; y<=n; y++) { if (A[x][y]) { if (y==p) continue; if (!v[y]) { d[y]=d[x]+1; dfs(y,x); } else if (!f) { c = d[x]-d[y]+1; f = true; } } } } int main() { cin >> n; for (int i=1; i<=n; i++) { for (int j=1; j<=n; j++) { A[i][j]=0; } v[i]=false; d[i]=0; } for (int i=1; i<=n; i++) { int x, y; cin >> x >> y; A[x][y] = A[y][x] = 1; } d[1]=1; dfs(1,0); cout << c; return 0; } ^
www.pbinfo.ro permite evaluarea a două tipuri de probleme:
Problema Spanning Tree 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ă.