제출 #875279

#제출 시각아이디문제언어결과실행 시간메모리
875279Cyber_WolfNaboj (COCI22_naboj)C++17
0 / 110
85 ms17472 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #define lg long long #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const lg N = 2e5+5; vector<lg> adj[N]; lg in[N], state[N]; int main() { fastio; lg n, m; cin >> n >> m; for(int i = 0; i < m; i++) { lg u, v; cin >> u >> v; adj[u].push_back(v); in[v]++; } queue<lg> q; lg z = 0; for(int i = 1; i <= n; i++) { if(in[i]) continue; z++; q.push(i); } while(q.size()) { lg u = q.front(); q.pop(); for(auto it : adj[u]) { state[u] = true; in[it]--; if(!in[it]) { q.push(it); state[it] = false; z++; } } } if(z < n) { cout << "-1\n"; return 0; } cout << n << '\n'; for(int i = 1; i <= n; i++) { cout << i << ' ' << state[i] << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...