結果

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

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <random>
#include <iomanip>
#include <string>
#include <cmath>
#include <complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T>
using vi = vector<T>;
template<class T>
using vii = vector<vi<T>>;
template<class T>
using viii = vector<vii<T>>;
using P = pair<ll, int>;
void chmin(ll & x, ll y) { x = min(x, y); }
void chmax(ll& x, ll y) { x = max(x, y); }
struct mint {
const long long mod = 998244353;
long long x;
mint(long long x_ = 0) : x((x_% mod + mod) % mod) {}
mint& operator+=(const mint& other) {
x += other.x;
if (x >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint& other) {
x -= other.x;
if (x < 0) x += mod;
return *this;
}
mint& operator*=(const mint& other) {
x *= other.x;
x %= mod;
return *this;
}
mint& operator+=(const long long n) {
return *this += mint(n);
}
mint& operator-=(const long long n) {
return *this -= mint(n);
}
mint& operator*=(const long long n) {
return *this *= mint(n);
}
mint& operator=(const mint& other) {
x = other.x;
return *this;
}
mint& operator=(const long long n) {
x = n % mod;
return *this;
}
bool operator==(const mint& other) const {
return x == other.x;
}
bool operator!=(const mint& other) const {
return x != other.x;
}
mint operator-() const {
mint res(mod - x);
return res;
}
mint operator+(const mint& other) const {
mint res(x);
return res += other;
}
mint operator-(const mint& other) const {
mint res(x);
return res -= other;
}
mint operator*(const mint& other) const {
mint res(x);
return res *= other;
}
mint operator+(const long long n) const {
mint res(x);
mint other(n);
return res += other;
}
mint operator-(const long long n) const {
mint res(x);
mint other(n);
return res -= other;
}
mint operator*(const long long n) const {
mint res(x);
mint other(n);
return res *= other;
}
mint pow(long long n) const {
if (n == 0) return mint(1);
mint res = pow(n / 2);
res *= res;
if (n % 2) res *= *this;
return res;
}
mint inv() const {
return pow(mod - 2);
}
mint& operator/=(const mint& other) {
*this *= other.inv();
return *this;
}
mint operator/(const mint& other) const {
mint res(x);
return res /= other;
}
};
struct edge {
int to, idx;
};
int main()
{
int n;
cin >> n;
vi<int> a(n), b(n);
vii<edge> to(n);
vi<int> deg(n);
rep(i, n) {
cin >> a[i] >> b[i];
a[i]--, b[i]--;
to[a[i]].push_back({ b[i], i });
to[b[i]].push_back({ a[i], i });
deg[a[i]]++, deg[b[i]]++;
}
queue<int> q;
rep(i, n) {
if (deg[i] == 1) q.push(i);
}
vi<int> ans(n);
vi<bool> visited(n);
while (!q.empty()) {
int v = q.front();
q.pop();
visited[v] = true;
edge nv = to[v].front();
if (v > nv.to) ans[nv.idx] = 1;
else ans[nv.idx] = -1;
deg[nv.to]--;
if (deg[nv.to] == 1) q.push(nv.to);
}
rep(i, n) {
if (visited[i]) continue;
q.push(i);
while (!q.empty()) {
int v = q.front();
q.pop();
visited[v] = true;
for (edge nv : to[v]) {
if (ans[nv.idx] != 0) continue;
if (v > nv.to) ans[nv.idx] = 1;
else ans[nv.idx] = -1;
q.push(nv.to);
break;
}
}
break;
}
rep(i, n) cout << (ans[i] == 1 ? "<-" : "->") << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0