Submission #781679

# Submission time Handle Problem Language Result Execution time Memory
781679 2023-07-13T09:51:35 Z makanhulia Naboj (COCI22_naboj) C++17
0 / 110
114 ms 14192 KB
#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[200005] , b[200005] , fq[200005] , par[200005];
vector < int > adj[200005];
bool vis[200005];
vector < pair < int , int > > v;

void dfs(int cur){
   vis[cur] = true;
   v.pb(make_pair(cur , 1));
   for(int i : adj[cur]){
      if(!vis[i]){
         dfs(i);
      }
   }
}
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(root);
   if(root == 0){
      cout << "-1" << endl;
      return 0;
   }
   cout << v.size() - 1 << endl;
   for(int i = 1 ; i < v.size() ; i++){
      cout << v[i].first << " " << v[i].second << endl;
   }
}

Compilation message

naboj.cpp: In function 'int main()':
naboj.cpp:41:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |    for(int i = 1 ; i < v.size() ; i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 114 ms 14192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -