제출 #932907

#제출 시각아이디문제언어결과실행 시간메모리
932907Amirreza_FakhriNaboj (COCI22_naboj)C++17
110 / 110
151 ms15304 KiB
// 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 = 2e5+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 << ' ' << 1 << '\n';
    }
    return 0;
} 











컴파일 시 표준 에러 (stderr) 메시지

naboj.cpp: In function 'int32_t main()':
naboj.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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...