Submission #1107232

#TimeUsernameProblemLanguageResultExecution timeMemory
1107232santi3223Parachute rings (IOI12_rings)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define vl vector<ll> #define pb push_back #define ff(i, p, x) for (ll i = p; i < x; i++) #define all(a) (a).begin(), (a).end() #define ed "\n" //me faltan declarar los vectores xd void Init(int N_) { n = (long long)N_; Grafo.assign(n, vector<long long>()); } void Link(ll A, ll B){ A--; B--; gra[A].push_back(B); gra[B].push_back(A); grado[A]++; grado[B]++; } void dfs(ll nodo){ visitado[nodo] = true; for(auto &vecino : gra[nodo]){ if(!visitado[vecino]){ dfs(vecino); } } } bool esCadena(ll excluido){ fill(visitado.begin(), visitado.end(), false); ll componentes = 0; ff(i, 0, N){ if(i != excluido && !visitado[i]){ componentes++; dfs(i); } } return componentes == 1; // Solo debe haber un componente conectado ..? } int CountCritical(){ ll criticos = 0; ff(i, 0, N){ if(grado[i] <= 2){ if(esCadena(i)){ criticos++; } } } return criticos; } int main() { // Ejemplo de uso Init(7); cout << CountCritical() << ed; // Debería devolver 7 Link(1, 2); cout << CountCritical() << ed; // Debería devolver 7 Link(0, 5); cout << CountCritical() << ed; // Debería devolver 7 Link(2, 0); cout << CountCritical() << ed; // Debería devolver 7 Link(3, 2); cout << CountCritical() << ed; // Debería devolver 4 Link(3, 5); cout << CountCritical() << ed; // Debería devolver 3 Link(4, 3); cout << CountCritical() << ed; // Debería devolver 2 return 0; } //Por ahí va la idea, seguro da comp error, pero algo asi es la solución

Compilation message (stderr)

rings.cpp: In function 'void Init(int)':
rings.cpp:12:3: error: 'n' was not declared in this scope; did you mean 'yn'?
   12 |   n = (long long)N_;
      |   ^
      |   yn
rings.cpp:13:3: error: 'Grafo' was not declared in this scope
   13 |   Grafo.assign(n, vector<long long>());
      |   ^~~~~
rings.cpp: In function 'void Link(long long int, long long int)':
rings.cpp:18:5: error: 'gra' was not declared in this scope
   18 |     gra[A].push_back(B);
      |     ^~~
rings.cpp:20:5: error: 'grado' was not declared in this scope
   20 |     grado[A]++;
      |     ^~~~~
rings.cpp: In function 'void dfs(long long int)':
rings.cpp:25:5: error: 'visitado' was not declared in this scope
   25 |     visitado[nodo] = true;
      |     ^~~~~~~~
rings.cpp:26:24: error: 'gra' was not declared in this scope
   26 |     for(auto &vecino : gra[nodo]){
      |                        ^~~
rings.cpp: In function 'bool esCadena(long long int)':
rings.cpp:34:10: error: 'visitado' was not declared in this scope
   34 |     fill(visitado.begin(), visitado.end(), false);
      |          ^~~~~~~~
rings.cpp:36:14: error: 'N' was not declared in this scope
   36 |     ff(i, 0, N){
      |              ^
rings.cpp:6:40: note: in definition of macro 'ff'
    6 | #define ff(i, p, x) for (ll i = p; i < x; i++)
      |                                        ^
rings.cpp: In function 'int CountCritical()':
rings.cpp:48:14: error: 'N' was not declared in this scope
   48 |     ff(i, 0, N){
      |              ^
rings.cpp:6:40: note: in definition of macro 'ff'
    6 | #define ff(i, p, x) for (ll i = p; i < x; i++)
      |                                        ^
rings.cpp:49:12: error: 'grado' was not declared in this scope
   49 |         if(grado[i] <= 2){
      |            ^~~~~