답안 #781681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781681 2023-07-13T09:52:16 Z kebine Naboj (COCI22_naboj) C++17
0 / 110
105 ms 21256 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] , fq[600005] , par[500005];
vector < int > adj[500005];
bool vis[500005];
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++){
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 105 ms 21256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -