Submission #705023

# Submission time Handle Problem Language Result Execution time Memory
705023 2023-03-03T08:20:45 Z Paul_Liao_1457 Naboj (COCI22_naboj) C++17
25 / 110
162 ms 19344 KB
//記得跳題
//#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 f, int up){
  vis[now] = 1;
  if (up != -1) {
    ans.pb({now, up});
    what[now] = up;
    last[now] = ++t;
  }
  for (auto i:e[now]) if(i.F!=f){
    if(vis[i.F]) {
      ok = 0; return;
    }
    dfs(i.F,now,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,0,-1);
  
  if(!ok) {
    cout << -1 << endl; return 0;
  }

  cout << ans.size() << endl;
  for (auto i:ans) {
    cout << i.F << " " << i.S << endl;
  }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 5032 KB Output is correct
5 Correct 3 ms 5124 KB Output is correct
6 Correct 3 ms 5052 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Incorrect 3 ms 4948 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 144 ms 19216 KB Output is correct
2 Correct 137 ms 19216 KB Output is correct
3 Correct 57 ms 12476 KB Output is correct
4 Correct 149 ms 19184 KB Output is correct
5 Correct 141 ms 19180 KB Output is correct
6 Correct 162 ms 19244 KB Output is correct
7 Correct 138 ms 19176 KB Output is correct
8 Correct 111 ms 16524 KB Output is correct
9 Correct 147 ms 19344 KB Output is correct
10 Correct 131 ms 19140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 5032 KB Output is correct
5 Correct 3 ms 5124 KB Output is correct
6 Correct 3 ms 5052 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Incorrect 3 ms 4948 KB Output isn't correct
9 Halted 0 ms 0 KB -