Submission #781640

#TimeUsernameProblemLanguageResultExecution timeMemory
781640KritzanNaboj (COCI22_naboj)C++14
110 / 110
634 ms30136 KiB
#include <bits/stdc++.h> using namespace std; int n, m; pair<int ,int> arr[500005]; vector<pair<int ,int> > v[200005]; int ways[200005]; bool vis[200005]; int pnt[200005]; stack<pair<int,int> > s; queue<int> q; int main() { cin >> n >> m; for(int i =1 ; i <= m; i++) { int a, b; cin >> a >> b; arr[i] = {a, b}; v[a].push_back({b, i}); v[b].push_back({a, i}); pnt[a]++; ways[a]++; ways[b]++; } memset(vis, 0, sizeof(vis)); for(int i = 1; i <= n; i++) { if (ways[i] == pnt[i]) { s.push({i, 1}); q.push(i); vis[i] = true; } else if (pnt[i] == 0){ s.push({i, 0}); q.push(i); vis[i] = true; } } while(!q.empty()) { int cur = q.front(); q.pop(); for(int i = 0; i < v[cur].size(); i++) { int nxt = v[cur][i].first; int idx = v[cur][i].second; ways[nxt]--; ways[cur]--; pnt[arr[idx].first]--; if (!vis[nxt] && pnt[nxt] == 0) { s.push({nxt, 0}); q.push(nxt); vis[nxt] = true; } else if(!vis[nxt] && pnt[nxt] == ways[nxt]) { s.push({nxt, 1}); q.push(nxt); vis[nxt] = true; } } } if (s.size() == n) { cout << n << endl; while(!s.empty()) { cout << s.top().first << " " << s.top().second << endl; s.pop(); } } else { cout << -1 << endl; return 0; } }

Compilation message (stderr)

naboj.cpp: In function 'int main()':
naboj.cpp:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         for(int i = 0; i < v[cur].size(); i++) {
      |                        ~~^~~~~~~~~~~~~~~
naboj.cpp:69:18: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   69 |     if (s.size() == n) {
      |         ~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...