제출 #735642

#제출 시각아이디문제언어결과실행 시간메모리
735642MODDIBosses (BOI16_bosses)C++14
100 / 100
634 ms764 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef long long ll; typedef pair<long long, long long> pll; typedef pair<int,int> pii; typedef vector<long long> vl; typedef vector<int> vi; int n; vi G[5100]; vector<pii> ord; ll rez = 0, all = 0; bool vis[5100]; void bfs(int v, int br) { if(vis[v] and br!=ord.size()){bfs(ord[br].first, br+1); return;} else if(vis[v] and br==ord.size())return; vis[v]=true; all++; if(br==0)rez+=1; else rez+=ord[br-1].second; for(auto next : G[v]) { if(!vis[next] and br!=0){ord.push_back({next, ord[br-1].second+1});} else if (!vis[next] and br==0)ord.push_back({next, 2}); } if(br==ord.size())return; bfs(ord[br].first, br+1); } int main(){ cin>>n; for(int i = 0; i < n; i++){ int k; cin>>k; for(int j = 0; j < k; j++){ int a; cin>>a; a--; G[a].pb(i); } } ll ans = 1e9; for(int i = 0; i < n; i++){ rez = 0; all = 0; memset(vis, false, sizeof vis); ord.clear(); bfs(i, 0); // cout<<rez<<endl; if(all==n) ans = min(ans, rez); } cout<<ans<<endl; return 0; }

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

bosses.cpp: In function 'void bfs(int, int)':
bosses.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     if(vis[v] and br!=ord.size()){bfs(ord[br].first, br+1); return;}
      |                   ~~^~~~~~~~~~~~
bosses.cpp:18:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     else if(vis[v] and br==ord.size())return;
      |                        ~~^~~~~~~~~~~~
bosses.cpp:28:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     if(br==ord.size())return;
      |        ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...