답안 #957698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957698 2024-04-04T08:24:07 Z Oggy Bosses (BOI16_bosses) C++14
0 / 100
16 ms 48472 KB
#include<bits/stdc++.h>
// #define file "C:\\Users\\PC VUI\\Desktop\\CWistor\\VSCODE\\name"
#define file "bosses"
using namespace std; 

#define ll long long
#define MAX 100100
#define fi first
#define se second
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<long long>
#define mem(a, b) memset((a), (b), sizeof((a)))
#define all(c) (c).begin(), (c).end()
const int MOD = 1e9 + 7;
const int N = 2e6 + 6;
const ll M = (ll)1e18 + 7LL;
const ll INF = 1e18;
ll n, k, ind = 0;
vector<ll> adj[N];
ll vst[N];
queue<pll> q;
void run_with_file()
{
	if (fopen(file".inp", "r"))
	{
		freopen(file".inp", "r", stdin);
		freopen(file".out", "w", stdout);
	}
}
ll calc(ll v){
	q.push({v, 1});
	ll total = 0;
	vst[v] = ind;
	while(!q.empty()){
		pll x = q.front(); q.pop();
		total+= x.se;
		for(auto u : adj[x.fi]){
			if(vst[u] != ind){
				vst[u] = ind;
				q.push({u, x.se + 1});
			}
		}
	}
	for(ll i = 1; i <= n; ++i){
		if(vst[i] != ind) return INF;
	}
	return total;
}
void inp(){
	cin >> n >> k;
	for(ll i = 1; i <= n; ++i){
		cin >> k;
		for(ll j = 1; j <= k; ++j){
			ll v;
			cin >> v;
			adj[v].push_back(i);
		}
	}
	ll minx = INF;
	for(ll i = 1; i <= n; ++i){
		ind++;
		minx = min(minx, calc(i));
	}
	cout << minx;
}
int main()
{
	cin.tie(0)->sync_with_stdio(0);
	run_with_file(); 
	inp();
}

Compilation message

bosses.cpp: In function 'void run_with_file()':
bosses.cpp:29:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |   freopen(file".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:30:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   freopen(file".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 48472 KB Output is correct
2 Incorrect 11 ms 48472 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 48472 KB Output is correct
2 Incorrect 11 ms 48472 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 48472 KB Output is correct
2 Incorrect 11 ms 48472 KB Output isn't correct
3 Halted 0 ms 0 KB -