제출 #852284

#제출 시각아이디문제언어결과실행 시간메모리
852284Trisanu_DasNaboj (COCI22_naboj)C++17
110 / 110
248 ms20268 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<int> deg(n + 1), adj[n + 1], topo;
    int a, b;
    while(m--){
        cin >> a >> b;
        deg[b]++;
        adj[a].push_back(b);
    }
    queue<int> q;
    for(int i = 1; i <= n; i++) if(deg[i] == 0) q.push(i);
    while(!q.empty()){
        int u = q.front(); q.pop();
        topo.push_back(u);
        for(auto v : adj[u]){
            deg[v]--;
            if(deg[v] == 0) q.push(v);
        }
    }
    if(topo.size() != n) cout << -1;
    else {
      cout << n << '\n'; 
      for(auto x : topo) cout << x << ' ' << 0 << '\n';
    }
}

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

naboj.cpp: In function 'int main()':
naboj.cpp:25:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |     if(topo.size() != n) cout << -1;
      |        ~~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...