Submission #638289

#TimeUsernameProblemLanguageResultExecution timeMemory
638289delreyLogičari (COCI21_logicari)C++14
0 / 110
87 ms7028 KiB
#include <bits/stdc++.h> using namespace std; int n; vector <int> v[100000]; bool blue[100000], notBlue[100000]; int main() { cin>>n; for(int i = 0; i < n; i++) { int a, b; cin>>a>>b; a--; b--; v[a].push_back(b); v[b].push_back(a); } int res = 0; for(int i = 0; i < n; i++) { if(blue[i] || notBlue[i]) continue; blue[i] = true; res++; for(auto j : v[i]) for(auto t : v[j]) notBlue[t] = true; } for(int i = 0; i < n; i++) { bool seesBlue = false; for(auto j : v[i]) if(blue[j]) { seesBlue = true; break; } if(!seesBlue) { cout<<-1<<endl; return 0; } } cout<<res<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...