結果

問題 No.488 四角関係
ユーザー pazzle1230
提出日時 2017-02-24 22:38:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 465 ms / 5,000 ms
コード長 2,041 bytes
コンパイル時間 1,165 ms
コンパイル使用メモリ 104,368 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-02 23:09:54
合計ジャッジ時間 2,751 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define INF_LL 1e18
#define INF 1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using namespace std;
using ll = long long;
using PII = pair<int, int>;
template<typename T>
void chmax(T &a, T &b){
a = max(a, b);
}
template<typename T>
void chmin(T &a, T &b){
a = min(a, b);
}
class Union_find{
private:
vector<int> par;
vector<int> rank;
int n;
public:
Union_find(int a){
n = a;
for(int i = 0;i < n;i++){
par.push_back(i);
rank.push_back(0);
}
}
int find(int x){
if(par[x] == x){
return x;
}else{
return par[x] = find(par[x]);
}
}
void unite(int x, int y){
x = find(x);
y = find(y);
if(x == y) return;
if(rank[x] < rank[y]){
par[x] = y;
}else{
par[y] = x;
if(rank[x] == rank[y]) rank[x]++;
}
}
bool same(int x, int y){
return find(x) == find(y);
}
};
int powm(int x, int y, int m){
int res = 1;
REP(i, y){
res *= x;
res %= m;
}
return res;
}
vector<int> G[51];
map<vector<int>, bool> used;
int N, M;
int dfs(int v, vector<int> V, int b){
ll res = 0;
V.push_back(v);
if(V.size() == 4){
bool flag = false;
REP(i, G[V[0]].size()){
if(G[V[0]][i] == V[2]) return 0;
if(G[V[0]][i] == V[3]) flag = true;
}
REP(i, G[V[1]].size()){
if(G[V[1]][i] == V[3]) return 0;
}
if(!flag) return 0;
sort(all(V));
if(used[V]) return 0;
used[V] = true;
return 1;
}
REP(i, G[v].size()){
if(G[v][i] == b) continue;
res += dfs(G[v][i], V, v);
}
return res;
}
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> M;
ll res = 0;
REP(i, M){
int a, b;
cin >> a >> b;
G[a].push_back(b);
G[b].push_back(a);
}
REP(i, N){
res += dfs(i, vector<int>(), -1);
}
cout << res << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0