Submission #899107

#TimeUsernameProblemLanguageResultExecution timeMemory
899107duckindogLogičari (COCI21_logicari)C++14
10 / 110
71 ms6156 KiB
// from duckindog wth depression #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n; vector<int> ad[N]; int d[N]; int32_t main() { cin.tie(0)->sync_with_stdio(0); if (fopen("duck.inp", "r")) { freopen("duck.inp", "r", stdin); freopen("duck.out", "w", stdout); } cin >> n; for (int i = 1; i <= n; ++i) { int u, v; cin >> u >> v; ad[u].push_back(v); ad[v].push_back(u); } int answer = 1e9; for (int mask = 1; mask < (1 << n); ++mask) { for (int i = 1; i <= n; ++i) d[i] = (mask >> i - 1 & 1); bool good = 1; for (int i = 1; i <= n; ++i) { int cnt = 0; for (int v : ad[i]) cnt += d[v]; if (cnt != 1) good = 0; } int cnt = 0; for (int i = 1; i <= n; ++i) cnt += d[i]; if (good) answer = min(answer, cnt); } cout << (answer == 1e9 ? -1 : answer) << '\n'; }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:26:52: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   26 |     for (int i = 1; i <= n; ++i) d[i] = (mask >> i - 1 & 1);
      |                                                  ~~^~~
Main.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen("duck.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     freopen("duck.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...