結果
問題 | No.488 四角関係 |
ユーザー |
![]() |
提出日時 | 2017-02-24 22:51:24 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 13 ms / 5,000 ms |
コード長 | 2,359 bytes |
コンパイル時間 | 1,672 ms |
コンパイル使用メモリ | 161,460 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-01-02 23:30:07 |
合計ジャッジ時間 | 2,713 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include<bits/stdc++.h>#include<algorithm>#define range(i,a,b) for(int i = (a); i < (b); i++)#define rep(i,b) for(int i = 0; i < (b); i++)#define all(a) (a).begin(), (a).end()#define show(x) cerr << #x << " = " << (x) << endl;#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;const int INF = 2000000000;using namespace std;template < class BidirectionalIterator >bool next_combination ( BidirectionalIterator first1 ,BidirectionalIterator last1 ,BidirectionalIterator first2 ,BidirectionalIterator last2 ){if (( first1 == last1 ) || ( first2 == last2 )) {return false ;}BidirectionalIterator m1 = last1 ;BidirectionalIterator m2 = last2 ; --m2;while (--m1 != first1 && !(* m1 < *m2 )){}bool result = (m1 == first1 ) && !(* first1 < *m2 );if (! result ) {while ( first2 != m2 && !(* m1 < * first2 )) {++ first2 ;}first1 = m1;std :: iter_swap (first1 , first2 );++ first1 ;++ first2 ;}if (( first1 != last1 ) && ( first2 != last2 )) {m1 = last1 ; m2 = first2 ;while (( m1 != first1 ) && (m2 != last2 )) {std :: iter_swap (--m1 , m2 );++ m2;}std :: reverse (first1 , m1 );std :: reverse (first1 , last1 );std :: reverse (m2 , last2 );std :: reverse (first2 , last2 );}return ! result ;}template < class BidirectionalIterator > bool next_combination ( BidirectionalIterator first , BidirectionalIterator middle , BidirectionalIteratorlast ){return next_combination (first , middle , middle , last );}int main(){int n, m;int g[55][55] = {0};cin >> n >> m;rep(i,m){int a, b;cin >> a >> b;g[a][b] = g[b][a] = 1;}if(n <= 3){cout << 0 << endl;return 0;}vector<int> v;int ans = 0;rep(i,n) v.emplace_back(i);do{int sg[4][4];int cnt = 0;rep(i,4){int c = 0;rep(j,4){if(g[v[i]][v[j]]) c++;}if(c == 2) cnt++;}if(cnt == 4) ans++;}while(next_combination(v.begin(), v.begin() + 4, v.end()));cout << ans << endl;}