제출 #167167

#제출 시각아이디문제언어결과실행 시간메모리
167167egekabasKronican (COCI16_kronican)C++14
10 / 100
256 ms504 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ull, ull> pull; typedef pair<int, int> pii; typedef pair<ld, ld> pld; int val[25][25]; vector<pair<int, pii>> v; int n, k; int prt[25]; int find(int x){ if(prt[x] == x) return x; return prt[x] = find(prt[x]); } int merge(int x, int y){ x = find(x); y = find(y); prt[x] = y; } int bitcnt(int x){ int ret = 0; while(x > 0){ ret += x%2; x /= 2; } return ret; } int f(int bit){ int ret = 0; for(int i = 0; i < n; ++i) prt[i] = i; int root = -1; for(int i = 0; i < n; ++i){ if((bit&(1<<i)) == 0) continue; if(root == -1) root = i; else merge(root, i); } for(auto u : v){ if(find(u.ss.ff) != find(u.ss.ss)){ ret += u.ff; merge(u.ss.ff, u.ss.ss); } } return ret; } int sfunc(pair<int, pii> a, pair<int, pii> b){return a.ff < b.ff;} int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); cin >> n >> k; for(int i = 0; i < n; ++i) for(int j = 0; j < n; ++j){ cin >> val[i][j]; if(i != j) v.pb({val[i][j], {i, j}}); } sort(v.begin(), v.end(), sfunc); int ans = 1e9; for(int i = 0; i < (1<<n); ++i){ if(bitcnt(i) == k){ ans = min(ans, f(i)); //cout << i << " " << f(i) << "\n"; } } cout << ans << "\n"; }

컴파일 시 표준 에러 (stderr) 메시지

kronican.cpp: In function 'int merge(int, int)':
kronican.cpp:27:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...