# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
735593 | 2023-05-04T11:30:38 Z | tigar | Bosses (BOI16_bosses) | C++14 | 629 ms | 852 KB |
#include <bits/stdc++.h> using namespace std; int n; vector<int>graff[5050]; bool check[5050]; vector<pair<int, int> >ord; int reezz=0, ans=INT_MAX, brr=0; void bfs(int v, int br) { //cout<<v<<endl; if(check[v] and br!=ord.size()){bfs(ord[br].first, br+1); return;} else if(check[v] and br==ord.size())return; check[v]=true; brr++; if(br==0)reezz+=1; else reezz+=ord[br-1].second; for(int i=0; i<graff[v].size(); i++) { if(!check[graff[v][i]] and br!=0){ord.push_back({graff[v][i], ord[br-1].second+1}); /*tree[v].push_back(graff[v][i]);*/} else if (!check[graff[v][i]] and br==0)ord.push_back({graff[v][i], 2}); } if(br==ord.size())return; bfs(ord[br].first, br+1); } int main() { ios_base::sync_with_stdio(false); //cin.tie(0); cout.tie(0); cin>>n; for(int i=1; i<=n; i++) { int k; cin>>k; for(int j=0; j<k; j++) { int a; cin>>a; graff[a].push_back(i); } } for(int i=1; i<=n; i++) { reezz=0; brr=0; for(int i=1; i<=n; i++)check[i]=false; ord.clear(); bfs(i, 0); if(brr==n)ans=min(ans, reezz); } cout<<ans; return 0; } /*4 1 2 1 1 1 1 1 1 9*/
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 19 ms | 596 KB | Output is correct |
13 | Correct | 15 ms | 672 KB | Output is correct |
14 | Correct | 136 ms | 648 KB | Output is correct |
15 | Correct | 4 ms | 596 KB | Output is correct |
16 | Correct | 507 ms | 756 KB | Output is correct |
17 | Correct | 629 ms | 840 KB | Output is correct |
18 | Correct | 579 ms | 852 KB | Output is correct |