# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1090107 | Onur_Ilgaz | Naboj (COCI22_naboj) | C++17 | 142 ms | 25000 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
int32_t main(){
fast
int n, m;
cin >> n >> m;
vector <vector <int> > adj(n + 1);
vector <int> to(n + 1);
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[b].push_back(a);
to[a]++;
}
vector <int> ans, zeros;
for(int i = 1; i <= n; i++) {
if(!to[i]) {
zeros.push_back(i);
}
}
while(!zeros.empty()) {
int node = zeros.back();
ans.push_back(node);
// cout << node << "\n";
zeros.pop_back();
for(auto it:adj[node]) {
to[it]--;
if(to[it] == 0) zeros.push_back(it);
}
}
if(ans.size() != n) {
cout << -1 << "\n";
return 0;
}
cout << n << "\n";
for(auto it:ans) {
cout << it << " " << 1 << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |