# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
782610 | 2023-07-14T06:28:09 Z | christinelynn | Naboj (COCI22_naboj) | C++17 | 108 ms | 13060 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; set<ll> st; 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); } void dfs2(ll now) { if(st.find(now) != st.end()) { flag = true; return ; } st.insert(now); vector<ll> adjn = adjl[now]; for (int i = 0; i < adjn.size(); ++i) { ll nxt = adjn[i]; if(st.find(nxt) != st.end()) { flag = true; return ; } dfs2(nxt); if (flag) { return ; } } } 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); } // Cek cycle // for (int i = 1; i <= n; ++i) // { // st.clear(); // dfs2(i); // if (flag) { // cout << "-1\n"; // return 0; // } // } for (int i = 1; i <= n; ++i) { if (visited[i]) { continue ; } dfs(i); } cout << ans.size() << "\n"; for (int i = ans.size()-1; i >= 0 ; --i) { cout << ans[i] << " 1\n"; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 5000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 13012 KB | Output is correct |
2 | Correct | 92 ms | 12968 KB | Output is correct |
3 | Correct | 49 ms | 9252 KB | Output is correct |
4 | Correct | 64 ms | 13056 KB | Output is correct |
5 | Correct | 71 ms | 13000 KB | Output is correct |
6 | Correct | 77 ms | 13008 KB | Output is correct |
7 | Correct | 64 ms | 13040 KB | Output is correct |
8 | Correct | 53 ms | 11200 KB | Output is correct |
9 | Correct | 108 ms | 12992 KB | Output is correct |
10 | Correct | 72 ms | 13060 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 5000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |