結果
問題 | No.2301 Namorientation |
ユーザー | Pechi |
提出日時 | 2023-05-12 22:22:35 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 393 ms / 3,000 ms |
コード長 | 2,574 bytes |
コンパイル時間 | 2,826 ms |
コンパイル使用メモリ | 188,216 KB |
実行使用メモリ | 53,248 KB |
最終ジャッジ日時 | 2024-05-06 12:25:53 |
合計ジャッジ時間 | 14,783 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 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 | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 182 ms
22,272 KB |
testcase_13 | AC | 154 ms
20,736 KB |
testcase_14 | AC | 353 ms
35,200 KB |
testcase_15 | AC | 201 ms
24,448 KB |
testcase_16 | AC | 295 ms
30,464 KB |
testcase_17 | AC | 179 ms
23,168 KB |
testcase_18 | AC | 300 ms
31,232 KB |
testcase_19 | AC | 141 ms
19,456 KB |
testcase_20 | AC | 296 ms
30,848 KB |
testcase_21 | AC | 194 ms
24,320 KB |
testcase_22 | AC | 200 ms
53,248 KB |
testcase_23 | AC | 197 ms
52,608 KB |
testcase_24 | AC | 164 ms
44,416 KB |
testcase_25 | AC | 114 ms
29,460 KB |
testcase_26 | AC | 144 ms
37,368 KB |
testcase_27 | AC | 354 ms
35,072 KB |
testcase_28 | AC | 365 ms
35,200 KB |
testcase_29 | AC | 393 ms
35,072 KB |
testcase_30 | AC | 353 ms
35,072 KB |
testcase_31 | AC | 349 ms
35,328 KB |
ソースコード
#define _USE_MATH_DEFINES #pragma GCC target("avx2") #pragma GCC optimize("O3") #define _USE_MATH_DEFINES #include<bits/stdc++.h> #include<unordered_map> #include<random> #include <array> #include <complex> using namespace std; #define LP(I,S,G) for (long long int I = (S); I < (G); ++I) #define IN(X) for (int in = 0; in < X.size(); in++)cin >> X[in] #define OUT(X) for (int in = 0; in < X.size(); in++)cout << X[in]<<" " #define SORT(X) sort((X).begin(), (X).end()) #define CSORT(X,Y) sort(X.begin(), X.end(),Y) #define COPY(X,Y) copy(X.begin(), X.end(), Y.begin()) #define ALL(X,Y) for (auto X = (Y).begin(); X != (Y).end(); X++) #define FULL(a) (a).begin(),(a).end() #define BFS(Q,S) for(Q.push(S);Q.size()!=0;Q.pop()) typedef long long int ll; typedef unsigned long long int ull; long long int M = 998244353; int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 }; ll MAX(ll A, ll B) { return ((A) > (B) ? (A) : (B)); } ll MIN(ll A, ll B) { return ((A) < (B) ? (A) : (B)); } inline long long int xor128() { static long long int x = 123456789, y = 362436069, z = 521288629, w = 88675123; long long int t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } ll dfs(ll now, ll past, vector<vector<ll>>& g, vector<ll>& v, vector<ll>& c) { v[now] = 1; ll ret = -1; ALL(i, g[now]) { if (*i == past)continue; if (v[*i] == 1) { c[now] = 1; if (ret == -1)ret = *i; } else { ll res = MAX(ret, dfs(*i, now, g, v, c)); if (res != -1)ret = res; if (ret != -1)c[now] = 1; } } if (ret == now)ret = -1; return ret; } int main() { ll n; cin >> n; vector<ll> u(n), v(n); vector<ll> ans(n, 0); vector<vector<ll>> g(n),G(n); vector<ll> vis(n, 0), c(n, 0); queue<ll> q; LP(i, 0, n) { cin >> u[i] >> v[i]; u[i]--, v[i]--; g[u[i]].push_back(i); g[v[i]].push_back(i); G[u[i]].push_back(v[i]); G[v[i]].push_back(u[i]); } dfs(0, -1, G, vis, c); ll now = 0; LP(i, 0, n) { if (c[i] == 1) { now = i; q.push(i); } } while (1) { bool ok = 1; ALL(i, g[now]) { ll gu = u[*i], gv = v[*i]; ll d = 1; if (gv == now) { swap(gu, gv); d *= -1; } if (ans[*i] == 0&&c[gv]==1) { ans[*i] = d; now = gv; ok = 0; break; } } if (ok)break; } while (q.size() != 0) { ll now = q.front(); q.pop(); ALL(i, g[now]) { ll gu = u[*i], gv = v[*i]; ll d = -1; if (gv == now) { swap(gu, gv); d *= -1; } if (ans[*i] == 0) { ans[*i] = d; q.push(gv); } } } LP(i, 0, n)cout << ((ans[i] == 1) ? "->" : "<-")<<"\n"; return 0; }