Submission #781639

# Submission time Handle Problem Language Result Execution time Memory
781639 2023-07-13T09:05:05 Z Kritzan Naboj (COCI22_naboj) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
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

naboj.cpp: In function 'int main()':
naboj.cpp:32:5: error: 'memset' was not declared in this scope
   32 |     memset(vis, 0, sizeof(vis));
      |     ^~~~~~
naboj.cpp:6:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
    5 | #include <queue>
  +++ |+#include <cstring>
    6 | using namespace std;
naboj.cpp:52: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]
   52 |         for(int i = 0; i < v[cur].size(); i++) {
      |                        ~~^~~~~~~~~~~~~~~
naboj.cpp:73: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]
   73 |     if (s.size() == n) {
      |         ~~~~~~~~~^~~~