Submission #711712

# Submission time Handle Problem Language Result Execution time Memory
711712 2023-03-17T11:32:20 Z 089487 Slagalica (COCI19_slagalica2) C++14
70 / 70
35 ms 7360 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("popcnt")
#include<bits/stdc++.h>
#define int long long
#define quick ios::sync_with_stdio(0);cin.tie(0);
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define repd(x,a,b) for(int x=a;x>=b;x--)
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define lowbit(x) (x&-x)
#define sz(x) (int)(x.size())
using namespace std;
typedef pair<int,int> pii;
void debug(){
    cerr<<"\n";
}
template<class T,class ...U>
void debug(T a,U ...b){
    cout<<a<<" ",debug(b...);
}
const int N=2e5+7;
const int INF=1e18;
int in[6];
int out[6];
vector<pii> v[6];
vector<int> res;
vector<int> v2[4];
void add_edge(int a,int b,int w){
    v[a].eb(mp(w,b));
    //debug(a,"=>",b);
    in[b]++;
    out[a]++;
}
pii e[8]={mp(1,2),mp(1,1),mp(2,2),mp(2,1),mp(0,2),mp(0,1),mp(1,4),mp(2,4)};
int t[N];
void dfs(int x){
    //debug(x,":",t[x]);
    //system("pause");
    for(int &i=t[x];i<sz(v[x]);){
        pii nw=v[x][i++];
        dfs(nw.S);
        res.eb(nw.F);
    }
}
signed main(){
    quick
    int n;
    int st=0;
    int ed=4;
    cin>>n;
    int stw=0;
    int ew=0;
    rep(i,1,n){
        int xi,ai;
        cin>>xi>>ai;
        add_edge(e[xi-1].F,e[xi-1].S,ai);
    }
    if(out[st]!=1||in[ed]!=1){
        cout<<"-1\n";
    }
    else{
        add_edge(ed,st,INF);
        rep(i,0,4){
            if(in[i]!=out[i]){
                cout<<"-1\n";
                return 0;
            }
            sort(all(v[i]));
        }
        //rep(i,0,4) debug(in[i],out[i]);
        dfs(st);
        reverse(all(res));
        rep(i,0,n-1) cout<<res[i]<<" \n"[i==n-1];
    }





}

Compilation message

slagalica.cpp: In function 'int main()':
slagalica.cpp:54:9: warning: unused variable 'stw' [-Wunused-variable]
   54 |     int stw=0;
      |         ^~~
slagalica.cpp:55:9: warning: unused variable 'ew' [-Wunused-variable]
   55 |     int ew=0;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 6452 KB Output is correct
2 Correct 21 ms 2100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 6328 KB Output is correct
2 Correct 15 ms 1992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1992 KB Output is correct
2 Correct 35 ms 6360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1936 KB Output is correct
2 Correct 35 ms 7132 KB Output is correct
3 Correct 32 ms 6244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 5124 KB Output is correct
2 Correct 14 ms 1976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 7160 KB Output is correct
2 Correct 24 ms 2012 KB Output is correct
3 Correct 34 ms 6148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 2076 KB Output is correct
2 Correct 27 ms 6344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 7360 KB Output is correct
2 Correct 14 ms 2740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 6132 KB Output is correct
2 Correct 23 ms 2656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 7252 KB Output is correct
2 Correct 16 ms 2792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 6116 KB Output is correct
2 Correct 15 ms 2580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 6232 KB Output is correct
2 Correct 15 ms 2748 KB Output is correct