結果

問題 No.2301 Namorientation
ユーザー erbowlerbowl
提出日時 2023-05-12 22:09:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 842 ms / 3,000 ms
コード長 4,380 bytes
コンパイル時間 2,345 ms
コンパイル使用メモリ 224,408 KB
実行使用メモリ 48,280 KB
最終ジャッジ日時 2024-05-06 12:11:43
合計ジャッジ時間 21,852 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 442 ms
29,760 KB
testcase_13 AC 393 ms
27,556 KB
testcase_14 AC 834 ms
48,132 KB
testcase_15 AC 514 ms
34,520 KB
testcase_16 AC 707 ms
42,260 KB
testcase_17 AC 513 ms
30,748 KB
testcase_18 AC 711 ms
42,992 KB
testcase_19 AC 363 ms
26,316 KB
testcase_20 AC 708 ms
42,604 KB
testcase_21 AC 492 ms
32,076 KB
testcase_22 AC 469 ms
48,280 KB
testcase_23 AC 472 ms
47,368 KB
testcase_24 AC 387 ms
40,936 KB
testcase_25 AC 438 ms
38,504 KB
testcase_26 AC 523 ms
47,796 KB
testcase_27 AC 812 ms
48,280 KB
testcase_28 AC 831 ms
48,148 KB
testcase_29 AC 840 ms
48,152 KB
testcase_30 AC 840 ms
48,156 KB
testcase_31 AC 842 ms
48,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long
// こっちを使おう!
// __builtin_popcountll

// modint
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() const { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
        is >> x.val;
        x.val %= MOD;
        if (x.val < 0) x.val += MOD;
        return is;
    }
    friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD>& r, long long n) noexcept {
        if (n == 0) return 1;
        if (n < 0) return modpow(modinv(r), -n);
        auto t = modpow(r, n / 2);
        t = t * t;
        if (n & 1) t = t * r;
        return t;
    }
    friend constexpr Fp<MOD> modinv(const Fp<MOD>& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        return Fp<MOD>(u);
    }
};

// const int MOD = 1000000007;
const int MOD = 998244353;
using mint = Fp<MOD>;


signed main(){
    ll n;
    std::cin >> n;
    vector<set<ll>> edges(n);
    map<pair<ll,ll>,ll> mi;
    vector<bool> im(n); //true -> 
    for (int i = 0; i < n; i++) {
        ll a,b;
        std::cin >> a>>b;
        a--;b--;
        edges[a].insert(b);
        edges[b].insert(a);
        mi[{a,b}]=i;
    }
    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
    for (int i = 0; i < n; i++) {
        pq.push({edges[i].size(), i});
    }
    
    ll last = 0;
    
    while(!pq.empty()){
        auto [size, i] = pq.top();pq.pop();
        if(size!=edges[i].size())continue;
        
        if(edges[i].size()==1){
            for (auto e : edges[i]) {
                // std::cout << i<<" "<<e << std::endl;
                if(i<e){
                    im[mi[{i,e}]]=true;
                }else{
                    im[mi[{e,i}]]=false;
                }
                edges[i].erase(e);
                edges[e].erase(i);
                pq.push({edges[e].size(),e});
                break;
            }
        }else{
            last = i;
            break;
        }
    }
    ll now = last;
    ll prev = -1;
    while(true){
        for (auto e : edges[now]) {
            if(e==prev)continue;
            //  std::cout << now<<" "<<e << std::endl;
            if(now<e){
                 im[mi[{now,e}]]=true;
            }else{
                 im[mi[{e,now}]]=false;
            }
            prev = now;
            now = e;
            break;
        }
        if(now==last)break;
    }
    for (int i = 0; i < n; i++) {
        if(im[i]){
            std::cout << "->" << std::endl;
        }else{
            std::cout << "<-" << std::endl;
        }
    }
}
0