結果
問題 |
No.3031 曲面の向き付け
|
ユーザー |
|
提出日時 | 2025-02-21 23:15:51 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,335 ms / 2,000 ms |
コード長 | 2,069 bytes |
コンパイル時間 | 6,919 ms |
コンパイル使用メモリ | 333,828 KB |
実行使用メモリ | 65,280 KB |
最終ジャッジ日時 | 2025-02-21 23:16:25 |
合計ジャッジ時間 | 22,734 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using mint = atcoder::static_modint<998244353>; // // using mint = atcoder::static_modint<1000000007>; using ld = long double; using ll = long long; #define mp(a,b) make_pair(a,b) #define rep(i,s,n) for(int i=s; i<(int)n; i++) const vector<int> dx{1,0,-1,0},dy{0,1,0,-1}; int main(){ int n;cin >> n; vector<vector<int>> V(n,vector<int>(3)); set<vector<int>> G; map<vector<int>,vector<int>> E_to_V; rep(i,0,n){ rep(j,0,3)cin >> V[i][j]; G.insert(V[i]); rep(j,0,3){ vector<int> S; S.push_back(V[i][j]); S.push_back(V[i][(j+1)%3]); if(S[0]>S[1])swap(S[0],S[1]); E_to_V[S].push_back(i); } } queue<int> Q; vector<int> d(n); rep(i,0,n)if(d[i]==0){ Q.push(i); d[i]=1; while(Q.size()){ auto x=Q.front();Q.pop(); rep(i,0,3){ vector<int> S; S.push_back(V[x][i]); S.push_back(V[x][(i+1)%3]); if(S[0]>S[1])swap(S[0],S[1]); if(!E_to_V.count(S))continue; auto c=E_to_V[S]; if(c.size()>=3){ cout<<"NO\n"; return 0; } if(c.size()==2){ int y=c[0]; if(x==y)y=c[1]; bool same=true; rep(j,0,3)rep(k,0,3){ if(V[x][j]==V[y][k] && V[x][(j+1)%3]==V[y][(k+1)%3])same=false; } int newd; if(same)newd=d[x]; else newd=-d[x]; if(d[y]==0){ d[y]=newd; Q.push(y); } else if(d[y]!=newd){ cout << "NO\n"; return 0; } } } } } cout << "YES\n"; }