# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
782472 | 2023-07-14T02:47:40 Z | christinelynn | Naboj (COCI22_naboj) | C++17 | 106 ms | 13492 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MAXN = 2e5 + 5; const ll MAXM = 5e5 + 5; ll n, m; vector<ll> adjl[MAXN], ans; bool visited[MAXN], flag = false; void dfs(ll now) { if (visited[now]) { flag = true; return ; } visited[now] = true; vector<ll> adjn = adjl[now]; for (int i = 0; i < adjn.size(); ++i) { ll nxt = adjn[i]; if (visited[nxt]) { continue ; } dfs(nxt); if (flag) { return ; } } ans.push_back(now); } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0; i < m; ++i) { ll tmpa, tmpb; cin >> tmpa >> tmpb; adjl[tmpb].push_back(tmpa); } for (int i = 1; i <= n; ++i) { if (visited[i]) { continue ; } dfs(i); if (flag) { cout << "-1\n"; return 0; } } cout << ans.size() << "\n"; for (int i = ans.size()-1; i >= 0 ; --i) { cout << ans[i] << " 1\n"; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4948 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 87 ms | 13212 KB | Output is correct |
2 | Correct | 79 ms | 13420 KB | Output is correct |
3 | Correct | 32 ms | 9640 KB | Output is correct |
4 | Correct | 94 ms | 13440 KB | Output is correct |
5 | Correct | 69 ms | 13424 KB | Output is correct |
6 | Correct | 106 ms | 13492 KB | Output is correct |
7 | Correct | 69 ms | 13452 KB | Output is correct |
8 | Correct | 51 ms | 11592 KB | Output is correct |
9 | Correct | 100 ms | 13448 KB | Output is correct |
10 | Correct | 75 ms | 13440 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 4948 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |