답안 #83026

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83026 2018-11-04T07:40:21 Z FedericoS Park (BOI16_park) C++14
0 / 100
4 ms 976 KB
#include <iostream>
#include <queue>
#include <assert.h>
using namespace std;
typedef long long int ll;

ll N,K;
ll x;
bool B[5005][5005],V[5005];
int P[5005];
queue<int> L;
vector<int> grafo[5005];
ll ans=1e18,res;
ll S[5005];

void DFS(int k){
	for(int f:grafo[k]){
		DFS(f);
		S[k]+=S[f];
	}
	S[k]++;
	res+=S[k];
}

int main(){

	cin>>N;
	for(int i=0;i<N;i++){
		cin>>K;
		assert(K);
		for(int j=0;j<K;j++){
			cin>>x;
			x--;
			B[i][x]=true;
		}
	}

	for(int i=0;i<N;i++){
		
		fill(V,V+N,false);
		L.push(i);
		V[i]=true;

		for(int j=0;j<N;j++)
			grafo[j].clear();
		fill(S,S+N,0);
		res=0;

		while(!L.empty()){
			for(int j=0;j<N;j++)
				if(!V[j] and B[j][L.front()]){
					grafo[L.front()].push_back(j);
					L.push(j);
					V[j]=true;
				}
			L.pop();
		}

		DFS(i);
		ans=min(ans,res);

	}

	cout<<ans;

}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 976 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -