# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
212720 | BThero | Making Friends on Joitter is Fun (JOI20_joitter2) | C++17 | 5090 ms | 37372 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define DBG 1
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>
//#include<ext/pb_ds/tree_policy.hpp>
//#include<ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) if (DBG) cerr << #x << " = " << x << endl;
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int MAXN = (int)5e3 + 5;
int adj[MAXN][MAXN];
int n, m, ans, sz;
pii Q[MAXN * MAXN];
void push() {
for (int i = 0; i < sz; ++i) {
int x = Q[i].fi;
int y = Q[i].se;
for (int z = 1; z <= n; ++z) {
if (z != x && z != y) {
if (adj[z][x] && !adj[z][y]) {
adj[z][y] = 1;
++ans;
if (adj[y][z]) {
Q[sz++] = mp(y, z);
}
}
else if (adj[z][y] && !adj[z][x]) {
adj[z][x] = 1;
++ans;
if (adj[x][z]) {
Q[sz++] = mp(x, z);
}
}
}
}
}
}
void solve() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; ++i) {
int u, v;
scanf("%d %d", &u, &v);
if (adj[u][v] == 0) {
adj[u][v] = 1;
++ans;
sz = 0;
if (adj[u][v] && adj[v][u]) {
Q[sz++] = mp(u, v);
}
for (int w = 1; w <= n; ++w) {
if (w != u && w != v && adj[v][w] && adj[w][v] && !adj[u][w]) {
adj[u][w] = 1;
++ans;
if (adj[w][u]) {
Q[sz++] = mp(u, w);
}
}
}
push();
}
printf("%d\n", ans);
}
}
int main() {
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |