Submission #863925

#TimeUsernameProblemLanguageResultExecution timeMemory
863925UnforgettableplPovjerenstvo (COI22_povjerenstvo)C++17
21 / 100
302 ms46680 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") /* ID: samikgo1 TASK: wormhole LANG: C++ */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; #define all(x) x.begin(),x.end() #define allr(x) x.rbegin(),x.rend() //#define f first //#define s second //#define x first //#define y second const int INF = 1e9; const ll modulo = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; //#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define int ll vector<int> adj[500001]; bool visited[500001]; bool colour[500001]; int c; void dfs(int x, bool col){ if(visited[x] and colour[x]!=col){ cout<<"-1\n";exit(0); } if(visited[x])return; if(col)c++; colour[x]=col; visited[x]=true; for(int&i:adj[x])dfs(i,!col); } void solve(){ int n,m; cin >> n >> m; for (int i = 0; i < m; i++) { int a,b;cin>>a>>b; adj[a].emplace_back(b); adj[b].emplace_back(a); } dfs(1,true); for(int i=1;i<=n;i++)if(!visited[i])dfs(i,true); cout << c << '\n'; for(int i=1;i<=n;i++)if(colour[i])cout<<i<<' '; cout << '\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); // int t; // cin >> t; // while(t--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...