답안 #238826

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238826 2020-06-13T06:35:29 Z Autoratch Bosses (BOI16_bosses) C++14
100 / 100
1459 ms 1144 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 5001;

int n,ans = INT_MAX,cn;
vector<int> adj[N],tre[N];
queue<int> q;
bool visited[N];
int res[N];

void dfs(int u)
{
    cn++;
    for(int v : tre[u]) dfs(v),res[u]+=res[v];
    res[u]++;
}

void solve(int s)
{
    for(int i = 1;i <= n;i++) tre[i].clear(),visited[i] = false,res[i] = 0;
    q.push(s),visited[s] = true;
    while(!q.empty())
    {
        int u = q.front(); q.pop();
        for(int v : adj[u]) if(!visited[v])
        {
            visited[v] = true;
            tre[u].push_back(v);
            q.push(v);
        }
    }
    cn = 0;
    dfs(s);
    if(cn!=n) return;
    int now = 0;
    for(int i = 1;i <= n;i++) now+=res[i];
    ans = min(ans,now);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        int am;
        cin >> am;
        while(am--)
        {
            int x;
            cin >> x;
            adj[x].push_back(i);
        }
    }
    for(int i = 1;i <= n;i++) solve(i);
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 640 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 5 ms 512 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 640 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 5 ms 640 KB Output is correct
10 Correct 5 ms 640 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 9 ms 768 KB Output is correct
13 Correct 11 ms 768 KB Output is correct
14 Correct 324 ms 1108 KB Output is correct
15 Correct 60 ms 768 KB Output is correct
16 Correct 1070 ms 896 KB Output is correct
17 Correct 1446 ms 1144 KB Output is correct
18 Correct 1459 ms 1144 KB Output is correct