Submission details
Task:Course Schedule
Sender:aalto26fh_010
Submission time:2026-10-02 13:26:52 +0300
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:43:17: error: return-statement with no value, in function returning 'int' [-fpermissive]
   43 |                 return;
      |                 ^~~~~~

Code

#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
#include <stack>

int main() {
    int n, m;
    std::cin >> n >> m;

    std::vector<std::vector<int>> course_needed_for(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        std::cin >> a >> b;
        course_needed_for[a-1].push_back(b-1);
    }

    std::vector<int> order(n);
    int order_idx = n-1;
    std::vector<int> process_state(n, 0);
    std::stack<int> stack;
    int last_start = 0;
    while (order_idx >= 0) {
        if (stack.empty()) {
            for (int i = last_start; i < n; ++i) {
                if (process_state[i] != 0) continue;
                stack.push(i);
            }
        }

        int course = stack.top();
        if (process_state[course] == 1) {
            stack.pop();
            process_state[course] = 2;
            order[order_idx--] = course;
            continue;
        }

        process_state[course] = 1;
        for (auto next_course : course_needed_for[course]) {
            if (process_state[next_course] == 1) {
                std::cout << "IMPOSSIBLE";
                return;
            }
            if (process_state[next_course] == 2) continue;
            stack.push(next_course);
        }
    }

    for (auto course : order) {
        std::cout << course << " ";
    }
}