Submission #782206

# Submission time Handle Problem Language Result Execution time Memory
782206 2023-07-13T16:21:08 Z christinelynn Naboj (COCI22_naboj) C++17
25 / 110
100 ms 14180 KB
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
  LL n,m;
  scanf("%lld %lld",&n,&m);
  vector<LL>adj[n+5];
  LL degree[n+5];
  memset(degree,0,sizeof(degree));
  for(LL a=1;a<=n;a++)
  {
    LL x,y;
    scanf("%lld %lld",&x,&y);
    adj[x].push_back(y);
    degree[y]++;
  }
  queue<LL>q;
  for(LL a=1;a<=n;a++)if(!degree[a])q.push(a);
  vector<int>v;
  
  while(!q.empty())
  {
    
    LL x=q.front();
    v.push_back(x);
    q.pop();
    for(LL a:adj[x])
    {
      degree[a]--;
      if(!degree[a])q.push(a);
    }
  }
  if(v.size()!=n)printf("-1\n");
  else{
    printf("%lld\n",v.size());
    for(LL a:v)
    {
      printf("%lld 0\n",a);
    }
  }
}

Compilation message

naboj.cpp: In function 'int main()':
naboj.cpp:34:14: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   34 |   if(v.size()!=n)printf("-1\n");
      |      ~~~~~~~~^~~
naboj.cpp:36:16: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   36 |     printf("%lld\n",v.size());
      |             ~~~^    ~~~~~~~~
      |                |          |
      |                |          std::vector<int>::size_type {aka long unsigned int}
      |                long long int
      |             %ld
naboj.cpp:7:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |   scanf("%lld %lld",&n,&m);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
naboj.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%lld %lld",&x,&y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 76 ms 14080 KB Output is correct
2 Correct 76 ms 14124 KB Output is correct
3 Correct 35 ms 7516 KB Output is correct
4 Correct 100 ms 14132 KB Output is correct
5 Correct 75 ms 14072 KB Output is correct
6 Correct 81 ms 14148 KB Output is correct
7 Correct 85 ms 14140 KB Output is correct
8 Correct 55 ms 11136 KB Output is correct
9 Correct 75 ms 14072 KB Output is correct
10 Correct 98 ms 14180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -