Submission #937384

# Submission time Handle Problem Language Result Execution time Memory
937384 2024-03-04T01:51:42 Z Darren0724 Making Friends on Joitter is Fun (JOI20_joitter2) C++17
0 / 100
4 ms 17496 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define all(x) x.begin(),x.end()
#define abcorz ios_base::sync_with_stdio(false);cin.tie(0);
const int N=200005;
const int mod=1e9+7;
const int INF=1e9;
namespace{
    vector<int> pa(N,-1);
    int Find(int k){
        return pa[k]<0?k:pa[k]=Find(pa[k]);
    }
    void onion(int a,int b,vector<set<int>> &adj){
        a=Find(a),b=Find(b);
        if(a==b)return;
        if(adj[a].size()>adj[b].size())swap(a,b);
        pa[b]+=pa[a];
        pa[a]=b;
        for(int j:adj[a]){
            adj[b].insert(j);
        }
    }
};
vector<int> adj[N],vis(N);
int dfs(int k){
    vis[k]=1;
    int cnt=1;
    for(int j:adj[k]){
        if(vis[j])continue;
        cnt+=dfs(j);
    }   
    return cnt;
}
int32_t main(){
    abcorz;
    set<pair<int,int>> s;
    int n,m;cin>>n>>m;
    vector<set<int>> adj(N);
    for(int j=1;j<=n;j++){
        adj[j].insert(j);
    }
    for(int i=0;i<m;i++){
        int a,b;cin>>a>>b;
        if(s.find({b,a})!=s.end()){
            onion(a,b,adj);
        }
        adj[Find(b)].insert(a);
        int ans=-n;
        for(int j=1;j<=n;j++){
            if(Find(j)!=j)continue;
            ans+=(-pa[j])*(int)(adj[j].size());
        }
        cout<<ans<<endl;
        s.insert({a,b});
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 17496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 17496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 17496 KB Output isn't correct
2 Halted 0 ms 0 KB -