結果

問題 No.2301 Namorientation
ユーザー FplusFplusFFplusFplusF
提出日時 2023-05-12 22:19:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,645 bytes
コンパイル時間 2,218 ms
コンパイル使用メモリ 214,680 KB
最終ジャッジ日時 2025-02-12 23:08:02
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
vector<vector<ll>> g;
vector<bool> vis;
vector<ll> v,s={};
void dfs(ll x,ll p){
    v.push_back(x);
    vis[x]=true;
    for(auto &i:g[x]){
        if(i==p) continue;
        if(!vis[i]) dfs(i,x);
        else{
            if((ll)s.size()==0) s=v;
        }
    }
    v.pop_back();
}
vector<ll> dist;
void dfs(ll x){
    for(auto &i:g[x]){
        if(dist[i]==-1){
            dist[i]=dist[x]+1;
            dfs(i);
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    g.resize(n);
    vis.resize(n,false);
    map<pll,ll> mp;
    vector<ll> ans(n,-1);
    vector<ll> a(n),b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
        mp[{a[i],b[i]}]=i;
        mp[{b[i],a[i]}]=i;
    }
    dfs(0,-1);
    rep(i,s.size()){
        ll x=s[i];
        ll y=s[(i+1)%(ll)s.size()];
        if(x<y) ans[mp[{x,y}]]=1;
        else ans[mp[{x,y}]]=0;
    }
    dist.resize(n,-1);
    dist[s.front()]=0;
    dfs(s.front());
    rep(i,n){
        if(ans[i]!=-1) continue;
        if((ll)dist[a[i]]<dist[b[i]]) ans[i]=0;
        else ans[i]=1;
    }
    rep(i,n){
        if(ans[i]==0) cout << "<-\n";
        else cout << "->\n";
    }
}
0