Skip to content

Instantly share code, notes, and snippets.

@Acarus
Created March 18, 2017 18:24
Show Gist options
  • Save Acarus/269aa3677e731e228dae98567bef020c to your computer and use it in GitHub Desktop.
Save Acarus/269aa3677e731e228dae98567bef020c to your computer and use it in GitHub Desktop.
A. Мишка и условие дружбы
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(int argc, char **argv) {
ios::sync_with_stdio(false);
srand(time(0));
#ifndef ONLINE_JUDGE
freopen("/home/acarus/input.txt", "r", stdin);
#endif
int n, m;
cin >> n >> m;
vector<set<int>> g(n + 1, set<int>());
int u, v;
for (int i = 0; i < m; ++i) {
cin >> u >> v;
g[u].insert(v);
g[v].insert(u);
}
for (int i = 1; i <= n; ++i) {
vector<pair<int, int>> pp;
for (int to1: g[i]) {
for (int to2: g[i]) {
if (to1 == to2) continue;
if (!g[to1].count(to2) || !g[to2].count(to1)) {
cout << "NO" << endl;
return 0;
}
pp.push_back(make_pair(to1, to2));
}
}
for (auto& p: pp) {
g[p.first].erase(p.second);
g[p.second].erase(p.first);
}
}
cout << "YES" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment