Submission #804425

#TimeUsernameProblemLanguageResultExecution timeMemory
804425Tunglam07Naboj (COCI22_naboj)C++17
0 / 110
232 ms10008 KiB
#include <bits/stdc++.h> using namespace std; vector<long long> vec[200005], ans; long long m ,n ,dp[200005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> m >> n; queue<long long> q; while(n--); { long long a ,b; cin >> a >> b; vec[a].push_back(b); dp[b]++; } for(int i=1;i<=m;i++) { if(dp[i]==0) { q.push(i); } } while(!q.empty()) { long long id = q.front(); q.pop(); ans.push_back(id); for(long long nx:vec[id]) { dp[nx]--; if(dp[nx]==0) { q.push(nx); } } } if(ans.size()!=m) { cout << -1; } else { cout << ans.size() <<endl; for(long long nx:ans) { cout << nx << " " << 0 << endl; } } }

Compilation message (stderr)

naboj.cpp: In function 'int main()':
naboj.cpp:14:2: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   14 |  while(n--);
      |  ^~~~~
naboj.cpp:15:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   15 |  {
      |  ^
naboj.cpp:42:15: 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]
   42 |  if(ans.size()!=m)
      |     ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...