結果
問題 | No.2301 Namorientation |
ユーザー | otoshigo |
提出日時 | 2023-05-12 21:40:19 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 169 ms / 3,000 ms |
コード長 | 1,802 bytes |
コンパイル時間 | 1,017 ms |
コンパイル使用メモリ | 89,456 KB |
実行使用メモリ | 37,504 KB |
最終ジャッジ日時 | 2024-05-06 11:25:29 |
合計ジャッジ時間 | 9,708 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 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 | 2 ms
5,376 KB |
testcase_07 | AC | 2 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 | 71 ms
15,616 KB |
testcase_13 | AC | 62 ms
14,592 KB |
testcase_14 | AC | 136 ms
23,936 KB |
testcase_15 | AC | 82 ms
17,024 KB |
testcase_16 | AC | 119 ms
21,120 KB |
testcase_17 | AC | 77 ms
16,128 KB |
testcase_18 | AC | 121 ms
21,376 KB |
testcase_19 | AC | 62 ms
13,824 KB |
testcase_20 | AC | 124 ms
21,248 KB |
testcase_21 | AC | 83 ms
16,896 KB |
testcase_22 | AC | 87 ms
37,504 KB |
testcase_23 | AC | 86 ms
36,992 KB |
testcase_24 | AC | 77 ms
31,616 KB |
testcase_25 | AC | 53 ms
20,004 KB |
testcase_26 | AC | 68 ms
24,024 KB |
testcase_27 | AC | 169 ms
24,064 KB |
testcase_28 | AC | 149 ms
24,064 KB |
testcase_29 | AC | 142 ms
23,936 KB |
testcase_30 | AC | 136 ms
23,936 KB |
testcase_31 | AC | 148 ms
24,064 KB |
ソースコード
#include<iostream> #include<vector> #include<algorithm> #include<tuple> using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i<n;i++) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} struct UnionFind { vector<int> par, siz; UnionFind(int n) : par(n,-1), siz(n,1) {} int find(int x){ if (par[x] == -1) return x; else{ par[x] = find(par[x]); return par[x]; } } bool same(int x, int y){ return find(x) == find(y); } int size(int x){ return siz[find(x)]; } void merge(int x, int y){ x = find(x); y = find(y); if (x == y) return; if (siz[x] < siz[y]) swap(x,y); siz[x] += siz[y]; par[y] = x; } }; void dfs(int x,int p,vector<vector<tuple<int,int,int>>>&g,vector<string>&ans){ for(auto[i,e,k]:g[x]){ if(i==p)continue; dfs(i,x,g,ans); if(k==1)ans[e]="<-"; else ans[e]="->"; } } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; vector<vector<tuple<int,int,int>>>g(n); UnionFind uf(n); int s=-1,t=-1; vector<string>ans(n); rep(i,n){ int a,b; cin>>a>>b; a--; b--; if(uf.same(a,b)){ s=a; t=b; ans[i]="->"; }else{ uf.merge(a,b); g[a].push_back(make_tuple(b,i,1)); g[b].push_back(make_tuple(a,i,0)); } } dfs(s,-1,g,ans); rep(i,n)cout<<ans[i]<<"\n"; }