結果
問題 | No.2301 Namorientation |
ユーザー | umezo |
提出日時 | 2023-05-12 23:10:38 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 398 ms / 3,000 ms |
コード長 | 932 bytes |
コンパイル時間 | 2,347 ms |
コンパイル使用メモリ | 209,420 KB |
実行使用メモリ | 19,584 KB |
最終ジャッジ日時 | 2024-11-28 19:52:42 |
合計ジャッジ時間 | 14,286 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; vector<int> G[200200]; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin>>n; vector<int> A(n),B(n),deg(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]); deg[A[i]]++; deg[B[i]]++; } priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> que; rep(i,n) que.push({G[i].size(),i}); vector<int> to(n,-1); while(que.size()){ auto [a,b]=que.top(); que.pop(); if(to[b]!=-1) continue; for(auto nv:G[b]){ if(to[nv]==b) continue; to[b]=nv; deg[b]--; deg[nv]--; que.push({deg[nv],nv}); break; } } rep(i,n){ if(to[A[i]]==B[i]) cout<<"->"<<endl; else cout<<"<-"<<endl; } return 0; }