답안 #782569

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782569 2023-07-14T05:36:21 Z kebine Naboj (COCI22_naboj) C++17
0 / 110
54 ms 10780 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
ll n,m,u,v;
bool vis[200200],cycle,in[200200];
vector<ll> adj[200200],ans;
int top[200200];
void dfs(ll x) {
  vis[x] = true;
  in[x] = true;
  for(auto i : adj[x]) {
    top[i]--;
    if(top[i] == 0) {
      ans.pb(i);
    }
    if(!vis[i]) {
      dfs(i);
    }
    else if(in[i]) {
      cycle = true;
      return;
    }
  }
  in[x] = false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  FOR(1,i,m) {
    cin >> u >> v;
    adj[v].pb(u);
    top[u]++;
  }
  FOR(1,i,n) {
    if(top[i] == 0) {
      dfs(i);
      if(cycle) {
        cout << -1 << endl;
        return 0;
      }
      break;
    }
  }
  for(auto i : ans) {
    cout << i << " 1" << endl;
  }
}

/*
5 5
3 1
2 3
4 2
5 2
5 4
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Incorrect 2 ms 4948 KB Unexpected end of file - int32 expected
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 10780 KB Integer parameter [name=d] equals to 85108, violates the range [0, 1]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Incorrect 2 ms 4948 KB Unexpected end of file - int32 expected
4 Halted 0 ms 0 KB -