# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
781698 | devariaota | Naboj (COCI22_naboj) | C++17 | 269 ms | 25664 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define sherina ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define int long long
#define INF 1e18
using namespace std;
int n, m ,a[500005] , b[500005], par[500005];
vector < int > adj[500005];
bool vis[500005];
vector < pair < int , int > > v;
void dfs(int cur, int start){
vis[cur] = true;
if(cur != start) v.pb(make_pair(cur , 1));
for(int i : adj[cur]){
if(!vis[i]){
dfs(i , start);
}
}
}
signed main(){
cin >> n >> m;
for(int i = 1 ; i <= m ; i++){
cin >> a[i] >> b[i];
adj[b[i]].pb(a[i]);
par[a[i]] = b[i];
}
int root = 0;
for(int i = 1 ; i <= n ; i++){
if(par[i] == 0){
root = i;
dfs(i , i);
}
}
if(root == 0){
cout << "-1" << endl;
return 0;
}
cout << v.size() << endl;
for(int i = 0 ; i < v.size() ; i++){
cout << v[i].first << " " << v[i].second << endl;
}
}
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... |