Submission #932904

# Submission time Handle Problem Language Result Execution time Memory
932904 2024-02-24T13:07:04 Z Amirreza_Fakhri Zemljište (COCI22_zemljiste) C++17
0 / 70
1 ms 600 KB
// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 5e2+5;

int n, m, cnt[maxn];
vector <int> adj[maxn], vec;
queue <int> q;

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        adj[--b].pb(--a);
        cnt[a]++;
    }
    for (int i = 0; i < n; i++) {
        if (!cnt[i]) q.push(i);
    }
    while (q.size()) {
        int v = q.front(); q.pop();
        vec.pb(v);
        for (int u : adj[v]) {
            cnt[u]--;
            if (!cnt[u]) q.push(u);
        }
    }
    if (vec.size() != n) cout << -1 << '\n';
    else {
        cout << n << '\n';
        for (int v : vec) cout << v << ' ' << 1 << '\n';
    }
    return 0;
} 











Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:42:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   42 |     if (vec.size() != n) cout << -1 << '\n';
      |         ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -