Task: | Course Schedule |
Sender: | AleksandrPolitov |
Submission time: | 2024-10-04 04:16:41 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.01 s | details |
#2 | ACCEPTED | 0.01 s | details |
#3 | ACCEPTED | 0.01 s | details |
#4 | ACCEPTED | 0.01 s | details |
#5 | ACCEPTED | 0.01 s | details |
#6 | ACCEPTED | 0.09 s | details |
#7 | ACCEPTED | 0.09 s | details |
#8 | ACCEPTED | 0.09 s | details |
#9 | ACCEPTED | 0.09 s | details |
#10 | ACCEPTED | 0.07 s | details |
#11 | ACCEPTED | 0.07 s | details |
#12 | ACCEPTED | 0.01 s | details |
#13 | ACCEPTED | 0.01 s | details |
#14 | ACCEPTED | 0.06 s | details |
#15 | ACCEPTED | 0.05 s | details |
#16 | ACCEPTED | 0.01 s | details |
#17 | ACCEPTED | 0.06 s | details |
Compiler report
input/code.cpp: In function 'int solve()': input/code.cpp:153:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare] 153 | if(res.size()!=n) { | ~~~~~~~~~~^~~
Code
#ifdef ONPC#define _GLIBCXX_DEBUG#endif#include <bits/stdc++.h>#define char unsigned char#define rep(i, a, b) for(int i=a; i< (b); ++i)#define all(x) begin(x), end(x)#define sz(x) (int)(x).size()#define eb emplace_back#define mp make_pair#define mt make_tuple#define fi first#define se second#define pb push_back#define LSOne(S) ((S) & -(S))using namespace std;// mt19937 rnd(239);mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());template <typename T> int sgn(T x) { return (T(0) < x) - (x < T(0)); }typedef long double T;typedef complex<T> pt;#define x real()#define y imag()template<class T>istream& operator>> (istream& is, complex<T>& p) {T value;is >> value;p.real(value);is >> value;p.imag(value);return is;}typedef long long ll;typedef long double ld;using pi = pair<ll, ll>;using vi = vector<ll>;template <class T>using pq = priority_queue<T>;template <class T>using pqg = priority_queue<T, vector<T>, greater<T>>;int popcnt(int x) { return __builtin_popcount(x); }int popcnt(ll x) { return __builtin_popcountll(x); }#define MIN(v) *min_element(all(v))#define MAX(v) *max_element(all(v))#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))void __print(int x) {cerr << x;}void __print(long x) {cerr << x;}void __print(long long x) {cerr << x;}void __print(unsigned x) {cerr << x;}void __print(unsigned long x) {cerr << x;}void __print(unsigned long long x) {cerr << x;}void __print(float x) {cerr << x;}void __print(double x) {cerr << x;}void __print(long double x) {cerr << x;}void __print(char x) {cerr << '\'' << x << '\'';}void __print(const char *x) {cerr << '\"' << x << '\"';}void __print(const string &x) {cerr << '\"' << x << '\"';}void __print(bool x) {cerr << (x ? "true" : "false");}template<typename T, typename V>void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}void _print() {cerr << "]\n";}template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}#ifdef DEBUG#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;#else#define dbg(x...)#endiftemplate<typename S, typename T = S> void chmin(S &s, T t) {s = s < t ? s : t;}template<typename S, typename T = S> void chmax(S &s, T t) {s = s > t ? s : t;}const int INF = 1e9; // 10^9 = 1B is < 2^31-1const ll LLINF = 4e18; // 4*10^18 is < 2^63-1const double EPS = 1e-9;const ll MOD = 1e9+7;const int N=1e5+10;vector<int> adj[N];vector<int> res;bool vis[N];int color[N];bool dag=true;void dfsCycle(int node) {if(!dag) return;color[node]=1;for(auto &w:adj[node]) {if(color[w]==1) {dag=false;return;} else if(color[w]==0) {dfsCycle(w);}}color[node]=2;}void dfs(int node) {vis[node]=true;for(auto &w:adj[node]) {if(!vis[w]) {dfs(w);}}res.pb(node);}int solve() {int n,m; std::cin >> n >> m;for (int i = 1; i <= n; i++) {vis[i]=false;}for (int i = 0; i < m; i++) {int a,b; std::cin >> a >> b;adj[a].pb(b);}for(int i=1; i<=n; i++) {if(color[i]==0) {dfsCycle(i);}}if(!dag) {std::cout << "IMPOSSIBLE" << std::endl;return 0;}for (int i = 1; i <= n; i++) {if(!vis[i]) {dfs(i);}}reverse(all(res));if(res.size()!=n) {std::cout << "IMPOSSIBLE" << std::endl;} else {for (int i = 0; i < n; i++) {std::cout << res[i] << " ";}std::cout << std::endl;}return 0;}int32_t main() {ios::sync_with_stdio(0);cin.tie(0);int TET = 1;//cin >> TET;for (int i = 1; i <= TET; i++) {#ifdef ONPCcout << "TEST CASE#" << i << endl;#endifif (solve()) {break;}#ifdef ONPCcout << "__________________________" << endl;#endif}#ifdef ONPCcerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;#endif}
Test details
Test 1
Verdict: ACCEPTED
input |
---|
10 20 5 2 2 4 8 9 6 4 ... |
correct output |
---|
5 7 10 2 1 8 3 9 6 4 |
user output |
---|
10 7 5 2 1 8 3 9 6 4 |
Test 2
Verdict: ACCEPTED
input |
---|
10 20 2 7 1 10 9 5 9 7 ... |
correct output |
---|
1 8 3 6 10 2 9 4 5 7 |
user output |
---|
8 1 3 6 10 2 9 4 5 7 |
Test 3
Verdict: ACCEPTED
input |
---|
10 20 8 5 2 3 10 1 9 1 ... |
correct output |
---|
4 6 7 9 10 2 8 3 1 5 |
user output |
---|
9 7 10 6 8 4 2 3 1 5 |
Test 4
Verdict: ACCEPTED
input |
---|
10 20 5 10 10 3 9 10 6 2 ... |
correct output |
---|
7 8 6 4 2 1 5 9 10 3 |
user output |
---|
8 7 6 4 2 5 1 9 10 3 |
Test 5
Verdict: ACCEPTED
input |
---|
10 20 2 9 4 8 9 1 10 6 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 6
Verdict: ACCEPTED
input |
---|
100000 200000 78359 8853 18190 30703 11401 30087 34627 11535 ... |
correct output |
---|
2 3 8 9 16 18 21 22 27 34 36 4... |
user output |
---|
99998 99996 99994 99993 99992 ... Truncated |
Test 7
Verdict: ACCEPTED
input |
---|
100000 200000 32395 2098 67067 31866 31867 67167 78488 33397 ... |
correct output |
---|
9 11 13 16 22 35 37 38 40 44 5... |
user output |
---|
100000 99994 99991 99986 99983... Truncated |
Test 8
Verdict: ACCEPTED
input |
---|
100000 200000 19035 36947 13730 46121 99449 77790 15626 11731 ... |
correct output |
---|
1 7 15 17 18 34 38 41 48 49 51... |
user output |
---|
100000 99998 99996 99993 99992... Truncated |
Test 9
Verdict: ACCEPTED
input |
---|
100000 200000 14188 9709 46541 20871 32203 88809 99879 54779 ... |
correct output |
---|
6 10 11 16 17 19 21 22 23 28 3... |
user output |
---|
99996 99992 99991 99986 99985 ... Truncated |
Test 10
Verdict: ACCEPTED
input |
---|
100000 200000 41882 61162 28138 18053 74649 74863 69760 74508 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 11
Verdict: ACCEPTED
input |
---|
100000 199998 1 100000 1 100000 2 100000 2 100000 ... |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
99999 99998 99997 99996 99995 ... Truncated |
Test 12
Verdict: ACCEPTED
input |
---|
2 2 1 2 2 1 |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 13
Verdict: ACCEPTED
input |
---|
6 6 1 2 2 3 4 3 4 5 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 14
Verdict: ACCEPTED
input |
---|
99999 149997 1 3 3 5 5 7 7 9 ... |
correct output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 15
Verdict: ACCEPTED
input |
---|
100000 149998 2 1 3 2 4 3 5 4 ... |
correct output |
---|
100000 99999 99998 99997 99996... |
user output |
---|
100000 99999 99998 99997 99996... Truncated |
Test 16
Verdict: ACCEPTED
input |
---|
6 6 1 2 1 3 2 4 3 5 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 17
Verdict: ACCEPTED
input |
---|
100000 200000 1 1 1 1 2 2 2 2 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |