Submission #781698

# Submission time Handle Problem Language Result Execution time Memory
781698 2023-07-13T10:08:56 Z devariaota Naboj (COCI22_naboj) C++17
0 / 110
269 ms 25664 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[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

naboj.cpp: In function 'int main()':
naboj.cpp:43: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]
   43 |    for(int i = 0 ; i < v.size() ; i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 269 ms 25664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -