#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);
}
cout << n << '\n';
vector<lg> a;
while(q.size())
{
lg u = q.front();
q.pop();
lg x = 0;
for(auto it : adj[u])
{
if(!x) a.push_back(u*2+1);
x++;
in[it]--;
if(!in[it])
{
q.push(it);
z++;
}
}
if(adj[u].empty())
{
a.push_back(u*2);
}
}
if(z < n)
{
cout << "-1\n";
return 0;
}
reverse(a.begin(), a.end());
for(auto it : a) cout << it/2 << ' ' << it%2 << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8028 KB |
Integer parameter [name=c] equals to -1, violates the range [1, 9] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
16324 KB |
Output is correct |
2 |
Correct |
78 ms |
18976 KB |
Output is correct |
3 |
Correct |
36 ms |
13744 KB |
Output is correct |
4 |
Correct |
77 ms |
18976 KB |
Output is correct |
5 |
Correct |
72 ms |
18892 KB |
Output is correct |
6 |
Correct |
83 ms |
19164 KB |
Output is correct |
7 |
Correct |
77 ms |
19012 KB |
Output is correct |
8 |
Correct |
53 ms |
16428 KB |
Output is correct |
9 |
Correct |
84 ms |
19148 KB |
Output is correct |
10 |
Correct |
80 ms |
18936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
8028 KB |
Integer parameter [name=c] equals to -1, violates the range [1, 9] |
2 |
Halted |
0 ms |
0 KB |
- |