이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int INF = 1e9 + 7;
vector<int> adj[5007], nex[5007];
bool vis[5007];
int val[5007];
void dfs(int u){
	int temp = 0;
	for(auto v : nex[u]){
		dfs(v);
		temp += val[v];
	}
	val[u] = temp + 1;
}
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		int k;
		cin >> k;
		while(k--){
			int temp;
			cin >> temp;
			adj[temp].push_back(i);
		}
	}
	int ans = INF;
	for(int i = 1; i <= n; i++){
		vis[i] = 1;
		queue<int> q;
		q.push(i);
		while(!q.empty()){
			int u = q.front();
			q.pop();
			for(auto v : adj[u]){
				if(!vis[v]){
					nex[u].push_back(v);
					vis[v] = 1;
					q.push(v);
				}
			}
		}
		bool chk = 1;
		for(int j = 1; j <= n; j++){
			if(!vis[j]){
				chk = 0;
				break;
			}
		}
		if(chk){
			dfs(i);
			int sum = 0;
			for(int j = 1; j <= n; j++)
				sum += val[j];
			ans = min(ans, sum);
		}
	}
	cout << ans << endl;
	return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |