#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fs first
#define sc second
vector<int> v[9];
int deg[9];
pii dif[] = {{0,0},{-1,-1},{-1,-1},{1,1},{1,-1},{-2,1},{-2,-1},{1,2},{-1,2}};
vector<int> ans;
const int mxn = 1e5+10;
bitset<mxn> vis;
struct Edge{
int to,val,id;
Edge(){}
Edge(int tt,int vv,int ii){
id = ii;
to = tt;
val = vv;
}
bool operator<(Edge &b){
return val<b.val;
}
};
vector<Edge> paths[9];
int ptr[9];
void dfs(int now){
while(!paths[now].empty()){
auto nxt = paths[now].back().to,val = paths[now].back().val;
paths[now].pop_back();
dfs(nxt);
ans.push_back(val);
}
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin>>n;
for(int i = 0;i<n;i++){
int a,b;
cin>>a>>b;
paths[dif[a].fs+4].push_back(Edge(dif[a].sc+4,b,i));
deg[dif[a].sc+4]++;
deg[dif[a].fs+4]--;
}
if(paths[2].size()!=1||deg[6] != 1){
cout<<"-1";
return 0;
}
// paths[6].push_back({2,0});
for(int i = 3;i<=5;i++){
if(deg[i] != 0){
cout<<-1;
return 0;
}
}
for(auto &i:paths)sort(i.rbegin(),i.rend());
dfs(2);
while(!ans.empty())cout<<ans.back()<<' ',ans.pop_back();return 0;
}
Compilation message
slagalica.cpp: In function 'int main()':
slagalica.cpp:60:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
60 | while(!ans.empty())cout<<ans.back()<<' ',ans.pop_back();return 0;
| ^~~~~
slagalica.cpp:60:61: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
60 | while(!ans.empty())cout<<ans.back()<<' ',ans.pop_back();return 0;
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1732 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
4688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1612 KB |
Output is correct |
2 |
Incorrect |
13 ms |
1996 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1764 KB |
Output is correct |
2 |
Incorrect |
14 ms |
1616 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
1612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
1604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
1612 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1808 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |