結果

問題 No.3719 Share the Tree
コンテスト
ユーザー yaaya
提出日時 2026-09-19 03:08:49
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
RE  
実行時間 -
コード長 2,101 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,487 ms
コンパイル使用メモリ 350,192 KB
実行使用メモリ 6,528 KB
平均クエリ数 1.00
最終ジャッジ日時 2026-09-19 03:09:04
合計ジャッジ時間 8,648 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other RE * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define ll long long
#define ull unsigned ll
#define ld long double
#define bl __int128_t
#define fi first
#define se second
#define vel vector<ll>
#define vvel vector<vel>
#define pll pair<ll,ll>
#define vepll vector<pll>
#define vvepll vector<vepll>
#define ves vector<string>
#define vem vector<mint>
#define vvem vector<vem>
#define pmm pair<mint,mint>
#define cleout(i) cout<<fixed<<setprecision(i)
template<class T>using PQ=priority_queue<T,vector<T>,greater<T>>;
//               上  右 下 左
vector<int> di={-1, 0, 1, 0};
vector<int> dj={ 0, 1, 0,-1};

vector<int> dx={ 0, 1, 0,-1};
vector<int> dy={ 1, 0,-1, 0};


vector<int> ddx={ 1, 1, 1, 0, -1, -1, -1, 0 };
vector<int> ddy={ 1, 0, -1, -1, -1, 0, 1, 1 };

ll inf=1000000000000000000;//1e18
// LLONG_MAX

mt19937_64 rng((ull)chrono::steady_clock::now().time_since_epoch().count());


void Alice(){
    ll N;
    cin>>N;
    cout<<2*N-3<<endl;
    vvel G(N);
    rep(i,0,N-1){
        ll x,y;
        cin>>x>>y;
        x--;
        y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    rep(i,0,N)sort(G[i].begin(),G[i].end());
    vel a;
    auto dfs=[&](auto self,ll now,ll par)->void {
        a.push_back(now);
        for(auto y:G[now]){
            if(y==par)continue;
            self(self,y,now);
            a.push_back(now);
        }
    };
    dfs(dfs,0,0);
    rep(i,1,a.size()-1)cout<<a[i]<<" ";
    cout<<endl;
}

void Bob(){
    ll N;
    cin>>N;
    cout<<2*N-3<<endl;
    vvel G(N);
    vel a(2*N-3);
    rep(i,0,2*N-3)cin>>a[i];
    ll now=0;
    set<pll> se;
    rep(i,0,a.size()){
        se.insert({min(a[i],now),max(a[i],now)});
        now=a[i];
    }
    for(auto it=se.begin();it!=se.end();it++){
        cout<<it->fi+1<<" "<<it->se+1<<endl;
    }
}


int main(){
    cin.tie(nullptr);
 	ios_base::sync_with_stdio(false);

    
    ll _;
    bool multitest=0;
    if(multitest)cin>>_;
    else _=1;
    string S;
    cin>>S;
    if(S[0]=='A')Alice();
    else Bob();
}
0