Submission #782483

#TimeUsernameProblemLanguageResultExecution timeMemory
782483kebineNaboj (COCI22_naboj)C++17
110 / 110
179 ms26292 KiB
# include <bits/stdc++.h> # define int long long # define vi vector<int> # define pb push_back # define pii pair<int, int> # define fi first # define se second # define endl '\n' # define jess ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; int n, m, rec[500005]; vi adj[500005]; bool vis[500005]; void solve() { cin >> n >> m; for(int i=1; i<=m; i++) { int a, b; cin >> a >> b; adj[b].pb(a); rec[a]++; } queue<int> q; vi v; for(int i=1; i<=n; i++) { if(rec[i]==0) { q.push(i); v.pb(i); } } while(!q.empty()) { int cur=q.front(); q.pop(); for(int i : adj[cur]) { if(vis[i]) continue; rec[i]--; if(rec[i]==0) { q.push(i); vis[i]=1; v.pb(i); } } } if(v.size()<n) { cout << -1 << endl; return; } cout << n << endl; for(int i : v) cout << i << " " << 1 << endl; } signed main() { jess; solve(); }

Compilation message (stderr)

naboj.cpp: In function 'void solve()':
naboj.cpp:46:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   46 |     if(v.size()<n) {
      |        ~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...