# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
532224 | 2022-03-02T14:03:14 Z | andecaandeci | Bosses (BOI16_bosses) | C++17 | 770 ms | 604 KB |
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second const int maxn = 5e3+1; int minum = 1e9; int main(){ int n; scanf("%d",&n); vector<int> adj[maxn]; for(int i=1;i<=n;i++){ int k; scanf("%d",&k); for(int j=0;j<k;j++){ int x; scanf("%d",&x); adj[x].pb(i); } } queue<int> q; int temp = 0; for(int i=1;i<=n;i++){ if(adj[i].empty()) continue; vector<bool> vis(n+1); q.push(i); vis[i] = 1; int node = 0,cnt = 1,ans = n; while(!q.empty()){ temp = q.front(); q.pop(); node++; for(auto it : adj[temp]){ if(!vis[it]){ vis[it] = 1; q.push(it); } } cnt--; if(cnt == 0){ ans += (n - node); cnt = (int) q.size(); } } if(node == n){ minum = min(minum,ans); } } printf("%d",minum); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 408 KB | Output is correct |
3 | Correct | 1 ms | 312 KB | Output is correct |
4 | Correct | 1 ms | 408 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 0 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 408 KB | Output is correct |
3 | Correct | 1 ms | 312 KB | Output is correct |
4 | Correct | 1 ms | 408 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 0 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 404 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 408 KB | Output is correct |
3 | Correct | 1 ms | 312 KB | Output is correct |
4 | Correct | 1 ms | 408 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 0 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 404 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 5 ms | 460 KB | Output is correct |
13 | Correct | 4 ms | 460 KB | Output is correct |
14 | Correct | 171 ms | 500 KB | Output is correct |
15 | Correct | 4 ms | 460 KB | Output is correct |
16 | Correct | 512 ms | 588 KB | Output is correct |
17 | Correct | 697 ms | 604 KB | Output is correct |
18 | Correct | 770 ms | 604 KB | Output is correct |