# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
782535 |
2023-07-14T04:31:46 Z |
gun_gan |
Naboj (COCI22_naboj) |
C++17 |
|
64 ms |
13168 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 2e5 + 5;
int N, M;
int deg[MX];
vector<int> g[MX];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> N >> M;
for(int i = 0; i < M; i++) {
int u, v;
cin >> u >> v;
g[v].push_back(u);
deg[u]++;
}
queue<int> q;
vector<int> ord;
for(int i = 1; i <= N; i++) {
if(!deg[i]) {
if(g[i].size()) ord.push_back(i);
q.push(i);
}
}
int cnt = 0;
while(!q.empty()) {
auto v = q.front(); q.pop();
cnt++;
for(auto u : g[v]) {
deg[u]--;
if(!deg[u]) {
if(g[u].size()) ord.push_back(u);
q.push(u);
}
}
}
if(cnt < N) {
cout << -1 << '\n';
return 0;
}
cout << ord.size() << '\n';
for(auto x : ord) {
cout << x << " " << 0 << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
64 ms |
13168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |