//記得跳題
//#pragma GCC optimize("O4,unroll_loops")
//#pragma GCC target("avx2")
#include<iostream>
#include<array>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<iomanip>
#include<bitset>
#include<tuple>
#include<random>
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define INF (ll)(2e18)
#define F first
#define S second
#define endl "\n"
#define AC ios::sync_with_stdio(0);
using namespace std;
vector<pair<int, int> > e[200005];
vector<pair<int, int> > ans;
int last[200005], t, what[200005];
bool vis[200005];
bool ok=1;
void dfs(int now, int up){
if (up != -1) {
ans.pb({now, up});
what[now] = up;
last[now] = ++t;
}
for (auto i:e[now]){
if(vis[i.F]) {
ok = 0; return;
}
dfs(i.F,i.S);
if(!ok) return;
}
}
vector<pair<int, int> > edge;
signed main(){
AC;
int n, m; cin >> n >> m;
FOR (i, 0, m) {
int a, b; cin >> a >> b;
edge.pb({a, b});
e[a].pb({b, 0});
e[b].pb({a, 1});
}
dfs(1,-1);
if(!ok) {
cout << -1 << endl; return 0;
}
cout << ans.size() << endl;
for (auto i:ans) {
cout << i.F << " " << i.S << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
322 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
384 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
322 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |