제출 #699036

#제출 시각아이디문제언어결과실행 시간메모리
699036RichemBosses (BOI16_bosses)C++14
100 / 100
867 ms692 KiB
#include <iostream> #include <vector> #include <queue> #include <stack> using namespace std; const int MAX_SOMMET = 5042, INF = 1e9; int nbSommet; vector<int> adj[MAX_SOMMET]; void input() { cin >> nbSommet; for(int sommet = 0; sommet < nbSommet; sommet++) { int nbVoisin; cin >> nbVoisin; for(int iVoisin = 0; iVoisin < nbVoisin; iVoisin++) { int idVoisin; cin >> idVoisin; adj[idVoisin-1].push_back(sommet); } } } bool vu[MAX_SOMMET]; int preced[MAX_SOMMET]; int rep[MAX_SOMMET] = {0}; int bfs(int depart) { for(int sommet = 0; sommet < nbSommet; sommet++) { vu[sommet] = rep[sommet] = 0; } queue<int> q; stack<int> ordre; q.push(depart); vu[depart] = 1; while(!q.empty()) { int cur = q.front(); q.pop(); ordre.push(cur); for(auto voisin : adj[cur]) { if(!vu[voisin]) { vu[voisin] = 1; preced[voisin] = cur; q.push(voisin); } } } if(ordre.size() != nbSommet) { return INF; } int total = 0; while(!ordre.empty()) { int cur = ordre.top(); ordre.pop(); rep[cur]++; if(cur != depart) { rep[preced[cur]] += rep[cur]; } total += rep[cur]; } return total; } int main() { input(); int valMin = INF; for(int sommet = 0; sommet < nbSommet; sommet++) { valMin = min(valMin, bfs(sommet)); } cout << valMin; }

컴파일 시 표준 에러 (stderr) 메시지

bosses.cpp: In function 'int bfs(int)':
bosses.cpp:35:34: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   35 |         vu[sommet] = rep[sommet] = 0;
      |                      ~~~~~~~~~~~~^~~
bosses.cpp:58:21: warning: comparison of integer expressions of different signedness: 'std::stack<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   58 |     if(ordre.size() != nbSommet) {
      |        ~~~~~~~~~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...