Created
January 7, 2023 22:14
-
-
Save ArthurLoboLobo/52f09061114754fc5cd4a7a7b74fd59a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int n, m, has[200010]; | |
vector<int> adj_out[200010]; | |
int main() { | |
cin >> n >> m; | |
for(int i = 1; i <= m; i++) { | |
int x,y; cin >> x >> y; | |
adj_out[x].push_back(y); | |
} | |
for(int u = 1; u <= n; u++) { | |
for(auto x : adj_out[u]) { | |
has[x] = 1; | |
} | |
for(auto w : adj_out[u]) { | |
// u -> w existe | |
for(auto v : adj_out[w]) { | |
// w -> v existe | |
if(has[v] == 0 && u != v) { | |
// u -> v não existe, então encontramos uma reposta | |
cout << u << " " << v << endl; | |
return 0; | |
} | |
} | |
} | |
for(auto x : adj_out[u]) { | |
has[x] = 0; | |
} | |
} | |
cout << -1 << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment