Submission #783682

# Submission time Handle Problem Language Result Execution time Memory
783682 2023-07-15T08:28:30 Z makanhulia Naboj (COCI22_naboj) C++17
0 / 110
388 ms 14904 KB
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define repp(i,n,k) for(int i=1;i<=n;i+=k)
#define repo(i,n,k) for(int i=0;i<n;i+=k)
#define pb push_back
using namespace std;

ll arr[200005];
vector<ll> adj[200005];
vector<ll> ans;

int main(){
  ll m,n;cin>>m>>n;
  queue<ll> q;
  for(int i=1;i<=n;i++){
    ll a,b;cin>>a>>b;
    adj[a].push_back(b);
    arr[b]++;
  }
  repp(i,n,1){
    if(arr[i]==0) q.push(i);
  }
  while(!q.empty()){
    ll cur=q.front();
    ans.pb(cur);
    q.pop();
    for(ll nx:adj[cur]){
      arr[nx]--;
      if(arr[nx]==0) q.push(nx);
    }
  }
  if(ans.size()!=m) cout<<"-1";
  else {
    cout<<ans.size()<<endl;
    for(ll nx:ans){
      cout<<nx<<" 0"<<endl;
    }
  }
}

Compilation message

naboj.cpp: In function 'int main()':
naboj.cpp:36: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]
   36 |   if(ans.size()!=m) cout<<"-1";
      |      ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Incorrect 3 ms 4948 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 388 ms 14904 KB Output is correct
2 Incorrect 120 ms 13696 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 2 ms 4948 KB Output is correct
3 Correct 2 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 2 ms 4948 KB Output is correct
6 Correct 2 ms 4948 KB Output is correct
7 Correct 2 ms 4948 KB Output is correct
8 Incorrect 3 ms 4948 KB Output isn't correct
9 Halted 0 ms 0 KB -