제출 #781262

#제출 시각아이디문제언어결과실행 시간메모리
781262devariaotaNaboj (COCI22_naboj)C++17
15 / 110
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; const int N=15; int n, m; vector <int> ls[N], topo; int in[N], bio[N]; queue <int> Q; void dfs(int node) { if (bio[node] == 1) { printf("-1\n"); exit(0); } if (bio[node] == 2) return; bio[node] = 1; for (int x:ls[node]) dfs(x); bio[node] = 2; } void solve() { for (int i=1; i<=n; ++i) { if (!bio[i]) dfs(i); if (in[i] == 0) { Q.push(i); } } while (!Q.empty()) { int node = Q.front(); Q.pop(); topo.push_back(node); for (int sus:ls[node]) { in[sus]--; if (in[sus] == 0) Q.push(sus); } } printf("%d\n", (int)topo.size()); for (int x:topo) printf("%d 0\n", x); } void load() { scanf("%d %d", &n, &m); for (int i=0; i<m; ++i) { int a, b; scanf("%d %d", &a, &b); ls[a].push_back(b); in[b]++; } } int main() { load(); solve(); return 0; }

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

naboj.cpp: In function 'void load()':
naboj.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
naboj.cpp:47:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...