# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
300738 | BeanZ | Making Friends on Joitter is Fun (JOI20_joitter2) | C++14 | 1 ms | 384 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.
// I_LOVE_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 2e3 + 5;
ll dp[N][N], tmp[N][N];
ll ans = 0;
ll n;
void construct(ll u, ll v){
if (tmp[u][v] == 0) ans++;
if (dp[v][u]){
for (int j = 1; j <= n; j++){
if (j == u || j == v) continue;
ll cost = 0;
cost = cost + dp[j][u];
cost = cost + dp[j][v];
if (cost == 1){
if (dp[j][u] == 0 && tmp[j][u] == 0) ans++, tmp[j][u] = 1, construct(j, u);
if (dp[j][v] == 0 && tmp[j][v] == 0) ans++, tmp[j][v] = 1, construct(j, v);
}
}
}
for (int j = 1; j <= n; j++){
if (u == j || v == j) continue;
if (dp[v][j] && dp[j][v] && tmp[u][j] == 0){
ans++;
tmp[u][j] = 1;
construct(u, j);
}
}
tmp[u][v] = 1;
dp[u][v] = 1;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
if (fopen("A.inp", "r")){
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
ll m;
cin >> n >> m;
for (int i = 1; i <= m; i++){
ll u, v;
cin >> u >> v;
construct(u, v);
cout << ans << endl;
}
}
/*
*/
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... |