//#define NDEBUG
#include <bits/stdc++.h>
#include <bits/extc++.h>
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
if(pvaspace) b << " "; pvaspace=true;\
b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define tiii tuple<int, int, int>
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) ((a) / (b) + !!((a) % (b)))
//#define TEST
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
const ll MOD = 1000000007;
const ll MAX = 2147483647;
template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
return o << '(' << p.F << ',' << p.S << ')';
}
vector<deque<pii>> g(4);
vector<int> ans;
void dfs(int now, int t){
// cerr << now << " " << t << "\n";
while(!g[now].empty()){
pii i = g[now].front();
g[now].pof;
dfs(i.S, i.F);
}
if(t != -1) ans.eb(t);
}
int main(){
StarBurstStream
int n;
cin >> n;
vector<int> from = {-1, 1, 1, 2, 2, 0, 0, 1, 2};
vector<int> to = {-1, 2, 1, 2, 1, 2, 1, 3, 3};
map<int, int> tmp;
vector<int> in(4), out(4);
for(int i = 0; i < n ;i++){
int x, a;
cin >> x >> a;
g[from[x]].eb(mp(a, to[x]));
tmp[a] = x;
out[from[x]]++;
in[to[x]]++;
}
for(int i = 1; i <= 2; i++){
if(in[i] != out[i]){
cout << "-1\n";
return 0;
}
}
for(int i = 0; i < 4; i++) lsort(g[i]);
dfs(0, -1);
reverse(iter(ans));
if(ans.size() != n || from[tmp[ans.front()]] != 0 || to[tmp[ans.back()]] != 3){
cout << "-1\n";
}
else printv(ans, cout);
return 0;
}
Compilation message
slagalica.cpp: In function 'int main()':
slagalica.cpp:93:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(ans.size() != n || from[tmp[ans.front()]] != 0 || to[tmp[ans.back()]] != 3){
~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
11632 KB |
Output is correct |
2 |
Correct |
62 ms |
6552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
11248 KB |
Output is correct |
2 |
Correct |
73 ms |
6192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
7032 KB |
Output is correct |
2 |
Correct |
87 ms |
11568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
6008 KB |
Output is correct |
2 |
Correct |
75 ms |
10988 KB |
Output is correct |
3 |
Correct |
86 ms |
11760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
9852 KB |
Output is correct |
2 |
Correct |
58 ms |
6520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
11248 KB |
Output is correct |
2 |
Correct |
57 ms |
6456 KB |
Output is correct |
3 |
Correct |
84 ms |
11372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
6136 KB |
Output is correct |
2 |
Correct |
79 ms |
11380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
13164 KB |
Output is correct |
2 |
Correct |
55 ms |
6032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
10992 KB |
Output is correct |
2 |
Correct |
65 ms |
6156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
12916 KB |
Output is correct |
2 |
Correct |
62 ms |
6620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
10860 KB |
Output is correct |
2 |
Correct |
55 ms |
6264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
11340 KB |
Output is correct |
2 |
Correct |
63 ms |
6520 KB |
Output is correct |