Submission #781698

#TimeUsernameProblemLanguageResultExecution timeMemory
781698devariaotaNaboj (COCI22_naboj)C++17
0 / 110
269 ms25664 KiB
#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)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...