Task: | Longest route |
Sender: | aalto2024h_002 |
Submission time: | 2024-10-23 16:55:49 +0300 |
Language: | C++ (C++20) |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | RUNTIME ERROR | 0.84 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.11 s | details |
#7 | WRONG ANSWER | 0.11 s | details |
#8 | WRONG ANSWER | 0.11 s | details |
#9 | TIME LIMIT EXCEEDED | -- | details |
#10 | TIME LIMIT EXCEEDED | -- | details |
#11 | ACCEPTED | 0.06 s | details |
#12 | ACCEPTED | 0.08 s | details |
#13 | ACCEPTED | 0.01 s | details |
#14 | ACCEPTED | 0.01 s | details |
#15 | WRONG ANSWER | 0.06 s | details |
#16 | ACCEPTED | 0.01 s | details |
#17 | WRONG ANSWER | 0.07 s | details |
#18 | ACCEPTED | 0.04 s | details |
#19 | ACCEPTED | 0.01 s | details |
#20 | ACCEPTED | 0.05 s | details |
#21 | ACCEPTED | 0.01 s | details |
Compiler report
input/code.cpp: In function 'int solve()': input/code.cpp:153:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare] 153 | for (int i = 0; i < res.size(); i++) { | ~~^~~~~~~~~~~~
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...) #endif template<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-1 const ll LLINF = 4e18; // 4*10^18 is < 2^63-1 const double EPS = 1e-9; const ll MOD = 1e9+7; const int N=1e5+10; int n, m; vector<int> adj[N], adjInv[N]; bool vis[N]; ll dp[N]; int solve() { std::cin >> n >> m; for (int i = 0; i < m; i++) { int a,b; std::cin >> a >> b; adj[a].pb(b); adjInv[b].pb(a); } for (int i = 1; i <= n; i++) { vis[i]=false; } for (int i = 1; i <= n; i++) { dp[i]=-1; } dp[1]=0; queue<int> q; q.push(1); while(!q.empty()) { int top=q.front(); q.pop(); if(vis[top]) continue; vis[top]=true; for(auto &w:adj[top]) { chmax(dp[w], dp[top]+1); if(!vis[w]) q.push(w); } } if(false) { for (int i = 1; i <= n; i++) { std::cout << dp[i] << " "; } std::cout << std::endl; } if(dp[n]==-1) { std::cout << "IMPOSSIBLE" << std::endl; return 0; } vector<int> res; int curr=n; while(curr!=1) { res.pb(curr); for(auto &w:adjInv[curr]) { if(dp[w]+1==dp[curr]) { curr=w; break; } } } res.pb(1); reverse(all(res)); std::cout << res.size() << std::endl; for (int i = 0; i < res.size(); 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 ONPC cout << "TEST CASE#" << i << endl; #endif if (solve()) { break; } #ifdef ONPC cout << "__________________________" << endl; #endif } #ifdef ONPC cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; #endif }
Test details
Test 1
Verdict: RUNTIME ERROR
input |
---|
10 10 2 6 1 2 4 6 5 6 ... |
correct output |
---|
5 1 2 5 6 10 |
user output |
---|
(empty) |
Test 2
Verdict: ACCEPTED
input |
---|
10 10 3 9 6 5 6 9 2 8 ... |
correct output |
---|
4 1 2 8 10 |
user output |
---|
4 1 2 8 10 |
Test 3
Verdict: ACCEPTED
input |
---|
10 10 5 10 4 10 8 7 7 10 ... |
correct output |
---|
3 1 4 10 |
user output |
---|
3 1 4 10 |
Test 4
Verdict: ACCEPTED
input |
---|
10 10 8 10 2 6 2 10 7 10 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 5
Verdict: ACCEPTED
input |
---|
10 10 8 4 2 10 1 3 4 9 ... |
correct output |
---|
5 1 8 7 2 10 |
user output |
---|
5 1 8 7 2 10 |
Test 6
Verdict: ACCEPTED
input |
---|
100000 200000 86085 57043 45527 29537 41919 84699 95993 82082 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 7
Verdict: WRONG ANSWER
input |
---|
100000 200000 10961 53490 59843 36636 40674 66772 32618 41570 ... |
correct output |
---|
31 1 37239 44082 21537 90572 7332... |
user output |
---|
12 1 14198 35116 26277 7322 42145... |
Test 8
Verdict: WRONG ANSWER
input |
---|
100000 200000 87375 76468 38855 27547 49415 83191 38572 1524 ... |
correct output |
---|
35 1 91343 59014 56722 34054 3875... |
user output |
---|
18 1 91343 59014 56722 34054 3875... Truncated |
Test 9
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 200000 17973 70097 19982 80323 96486 2404 75650 63274 ... |
correct output |
---|
36 1 25685 90292 59380 91058 2663... |
user output |
---|
(empty) |
Test 10
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 200000 74343 53088 97443 7885 64807 58252 9374 33312 ... |
correct output |
---|
28 1 26390 15278 11333 48479 6881... |
user output |
---|
(empty) |
Test 11
Verdict: ACCEPTED
input |
---|
100000 199998 1 100000 1 100000 2 100000 2 100000 ... |
correct output |
---|
2 1 100000 |
user output |
---|
2 1 100000 |
Test 12
Verdict: ACCEPTED
input |
---|
100000 199998 1 2 1 2 2 3 2 3 ... |
correct output |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 13
Verdict: ACCEPTED
input |
---|
2 1 1 2 |
correct output |
---|
2 1 2 |
user output |
---|
2 1 2 |
Test 14
Verdict: ACCEPTED
input |
---|
5 4 1 2 2 3 3 4 1 5 |
correct output |
---|
2 1 5 |
user output |
---|
2 1 5 |
Test 15
Verdict: WRONG ANSWER
input |
---|
99999 149997 1 3 3 5 5 7 7 9 ... |
correct output |
---|
99999 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
50001 1 2 3 5 7 9 11 13 15 17 19 21 ... Truncated |
Test 16
Verdict: ACCEPTED
input |
---|
3 2 1 3 3 2 |
correct output |
---|
2 1 3 |
user output |
---|
2 1 3 |
Test 17
Verdict: WRONG ANSWER
input |
---|
99999 149997 1 2 2 4 4 6 6 8 ... |
correct output |
---|
99999 1 3 2 5 4 7 6 9 8 11 10 13 12 ... |
user output |
---|
50001 1 3 2 4 6 8 10 12 14 16 18 20 ... Truncated |
Test 18
Verdict: ACCEPTED
input |
---|
100000 200000 1 2 1 3 1 4 1 5 ... |
correct output |
---|
IMPOSSIBLE |
user output |
---|
IMPOSSIBLE |
Test 19
Verdict: ACCEPTED
input |
---|
5 4 2 1 3 1 1 4 1 5 |
correct output |
---|
2 1 5 |
user output |
---|
2 1 5 |
Test 20
Verdict: ACCEPTED
input |
---|
100000 99999 99999 100000 99998 99999 99997 99998 99996 99997 ... |
correct output |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
user output |
---|
100000 1 2 3 4 5 6 7 8 9 10 11 12 13 ... Truncated |
Test 21
Verdict: ACCEPTED
input |
---|
4 4 3 1 3 4 1 2 2 4 |
correct output |
---|
3 1 2 4 |
user output |
---|
3 1 2 4 |