제출 #568071

#제출 시각아이디문제언어결과실행 시간메모리
568071abc864197532조이터에서 친구를 만드는건 재밌어 (JOI20_joitter2)C++17
1 / 100
5051 ms8916 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair <int, int> #define X first #define Y second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T a, U ...b) { cout << a << ' ', abc(b...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) { return o >> a.X >> a.Y; } template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) { return o << '(' << a.X << ", " << a.Y << ')'; } template <typename T> ostream& operator << (ostream& o, vector<T> a) { bool is = false; if (a.empty()) return o << "{}"; for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;} return o << '}'; } template <typename T> struct vv : vector <vector <T>> { vv(int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {} vv() {} }; template <typename T> struct vvv : vector <vv <T>> { vvv(int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {} vvv() {} }; #ifdef Doludu #define test(args...) abc("[" + string(#args) + "]", args) #define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); #else #define test(args...) void(0) #define owo ios::sync_with_stdio(false); cin.tie(0) #endif const int mod = 1e9 + 7, N = 2000, logN = 20, K = 48763; bool edge[N][N]; int ans = 0; int main () { owo; int n, q; cin >> n >> q; while (q--) { int u, v; cin >> u >> v, --u, --v; if (!edge[u][v]) { edge[u][v] = true, ans++; queue <pii> q; q.emplace(u, v); while (!q.empty()) { int u, v; tie(u, v) = q.front(); q.pop(); for (int x = 0; x < n; ++x) if (x != u && x != v) { if (edge[v][x] && edge[x][v] && !edge[u][x]) edge[u][x] = true, q.emplace(u, x), ans++; } if (edge[v][u]) { for (int x = 0; x < n; ++x) if (x != u && x != v) { if (edge[x][u] && !edge[x][v]) edge[x][v] = true, q.emplace(x, v), ans++; if (edge[x][v] && !edge[x][u]) edge[x][u] = true, q.emplace(x, u), ans++; } } } } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...