답안 #852266

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852266 2023-09-21T14:03:47 Z Trisanu_Das Naboj (COCI22_naboj) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n, m; cin >> n >> m;
  int deg[n + 1], u, v; memset(deg, 0, sizeof(deg));
  vector<int> adj[n + 1];
  while(m--){
    cin >> v >> u;
    adj[u].push_back(u); deg[u]++;
  }
  vector<int> toposort;
  queue<int> q;
  for(int i = 1; i < n + 1; i++) if(deg[i] == 0) q.push(i);
  while(!q.empty()){
    int u = q.front(); q.pop;
    toposort.push_back(u);
    for(v : adj[u]){
      deg[v]--; if(deg[v] == 0) q.push_back(v);
    }
  }
  if(toposort.size() != n) cout << -1 << '\n';
  else{
    cout << n << '\n';
    for(auto u : toposort) cout << u << ' ' << 0 << '\n';
  }
}

Compilation message

naboj.cpp: In function 'int main()':
naboj.cpp:16:26: error: invalid use of non-static member function 'void std::queue<_Tp, _Sequence>::pop() [with _Tp = int; _Sequence = std::deque<int, std::allocator<int> >]'
   16 |     int u = q.front(); q.pop;
      |                        ~~^~~
In file included from /usr/include/c++/10/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from naboj.cpp:1:
/usr/include/c++/10/bits/stl_queue.h:298:7: note: declared here
  298 |       pop()
      |       ^~~
naboj.cpp:18:11: error: found ':' in nested-name-specifier, expected '::'
   18 |     for(v : adj[u]){
      |           ^
      |           ::
naboj.cpp:18:9: error: 'v' is not a class, namespace, or enumeration
   18 |     for(v : adj[u]){
      |         ^
naboj.cpp:21:3: error: expected primary-expression before '}' token
   21 |   }
      |   ^
naboj.cpp:20:6: error: expected ';' before '}' token
   20 |     }
      |      ^
      |      ;
   21 |   }
      |   ~   
naboj.cpp:21:3: error: expected primary-expression before '}' token
   21 |   }
      |   ^
naboj.cpp:20:6: error: expected ')' before '}' token
   20 |     }
      |      ^
      |      )
   21 |   }
      |   ~   
naboj.cpp:18:8: note: to match this '('
   18 |     for(v : adj[u]){
      |        ^
naboj.cpp:21:3: error: expected primary-expression before '}' token
   21 |   }
      |   ^
naboj.cpp:22:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |   if(toposort.size() != n) cout << -1 << '\n';
      |      ~~~~~~~~~~~~~~~~^~~~