제출 #1047139

#제출 시각아이디문제언어결과실행 시간메모리
1047139Arturgo9월 (APIO24_september)C++17
100 / 100
240 ms27780 KiB
#include "september.h" #include <bits/stdc++.h> using namespace std; int solve( int nbSommets, int nbOrdres, vector<int> parents, vector<vector<int>> ordres ) { vector<vector<int>> sommetsAvant(nbSommets); vector<vector<int>> sommetsApres(nbSommets); auto ajoute = [&](int avant, int apres) { sommetsAvant[apres].push_back(avant); sommetsApres[avant].push_back(apres); }; for(int u = 1;u < nbSommets;u++) { ajoute(u, parents[u]); } for(vector<int>& ordre : ordres) { for(int i = 1;i < (int)ordre.size();i++) { ajoute(ordre[i - 1], ordre[i]); } } vector<bool> estVu(nbSommets, false); vector<int> postOrdre; auto calc_ordre = [&](auto self, int u) -> void { if(estVu[u]) return; estVu[u] = true; for(int v : sommetsAvant[u]) { self(self, v); } postOrdre.push_back(u); }; calc_ordre(calc_ordre, 0); fill(estVu.begin(), estVu.end(), false); auto calc_cfc = [&](auto self, int u) -> void { if(estVu[u]) return; estVu[u] = true; for(int v : sommetsApres[u]) { self(self, v); } }; int nbCFC = 0; while(!postOrdre.empty()) { int u = postOrdre.back(); postOrdre.pop_back(); if(!estVu[u]) { calc_cfc(calc_cfc, u); nbCFC++; } } return nbCFC - 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...