# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1209515 | cpdreamer | Naboj (COCI22_naboj) | C++20 | 340 ms | 15680 KiB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void file(){
freopen("input.txt.txt","r",stdin);
freopen("output.txt.txt","w",stdout);
}
const ll mod=(ll)1e9+7;
#define V vector
#define P pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
bool guess(int a, int b) {
cout << "? " << a << ' ' << b << endl;
bool res;
cin >> res;
return res;
}
V<int>adj[(int)2e5+1];
stack<int>st;
bool flag=true;
void dfs(int n,int state[]){
if(state[n]==1){
flag=false;
return;
}
if(state[n]==2){
return;
}
state[n]=1;
for(auto u:adj[n]){
dfs(u,state);
}
state[n]=2;
st.push(n);
}
void solve(){
int n;
cin>>n;
int m;
cin>>m;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
adj[b].pb(a);
}
int state[n+1];
memset(state,0,sizeof(state));
for(int i=1;i<=n;i++){
if(state[i]==0){
dfs(i,state);
if(!flag){
cout<<-1<<endl;
return;
}
}
}
cout<<n<<endl;
while(!st.empty()){
cout<<st.top()<<" "<<1<<endl;
st.pop();
}
}
int main() {
// file();
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |