답안 #968873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968873 2024-04-24T08:14:24 Z angella 조이터에서 친구를 만드는건 재밌어 (JOI20_joitter2) C++17
컴파일 오류
0 ms 0 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

ll n, m, ans, sz[N], par[N];
set<pii> glob;
set<int> eout[N], ein[N], st[N];

int getPar(int v) {return (par[v]==0 ? v : par[v]=getPar(par[v]));}

void merge(int v, int u) {
    v=getPar(v), u=getPar(u);
    if(u == v) return;
    if(sz[v] < sz[u]) swap(v,u);
    ans += (sz[v]*size(st[u]) + sz[u]*size(st[v]));
    // fuck(ans);
    par[u] = v;
    sz[v] += sz[u];

    for(auto it : st[u]) {
        if(st[v].find(it)!=st[v].end()) ans-=sz[v];
        else st[v].insert(it);
    }
    eout[u].erase(v);
    eout[v].erase(u);
    ein[v].erase(u);
    ein[u].erase(v);
    for(auto it : eout[u]) {
        ein[it].erase(u);
        ein[it].insert(v);
        eout[v].insert(it);
        if(eout[it].find(v) != eout[it].end()) glob.insert({it,v});
    }
    for(auto it : ein[u]) {
        eout[it].erase(u);
        eout[it].insert(v);
        ein[v].insert(it);
        if(ein[it].find(v) != ein[it].end()) glob.insert({it,v});
    }
}

int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>n>>m;
    fill(sz+1, sz+n+1, 1);
    for(int i=1; i<=n; i++) st[i].insert(i);
    for(int v,u,i=1; i<=m; i++) {
        cin>>v>>u;
        if(getPar(v)!=getPar(u) && st[pu].find(v)==st[pu].end()) {
            int pv=getPar(v), pu=getPar(u);
            eout[pv].insert(pu);
            ein[pu].insert(pv);
            st[pu].insert(v);
            ans += sz[pu];
            if(eout[pu].find(pv) != eout[pu].end()) {
                glob.insert({v, u});
                while(size(glob) > 0) {
                    pii tmp = *(glob.begin());
                    if(getPar(tmp.F)!=getPar(tmp.S))merge(getPar(tmp.F), getPar(tmp.S));
                    glob.erase(tmp);
                }
            }
        }
        cout<<ans<<endl;
        // if(i == 8) {
        //     for(int j=1; j<=n; j++) fuck(getPar(j));
        // }
    }

	return 0;
}

Compilation message

joitter2.cpp: In function 'int main()':
joitter2.cpp:88:39: error: 'pu' was not declared in this scope; did you mean 'u'?
   88 |         if(getPar(v)!=getPar(u) && st[pu].find(v)==st[pu].end()) {
      |                                       ^~
      |                                       u
joitter2.cpp:89:31: error: redeclaration of 'int pu'
   89 |             int pv=getPar(v), pu=getPar(u);
      |                               ^~
joitter2.cpp:88:39: note: '<typeprefixerror>pu' previously declared here
   88 |         if(getPar(v)!=getPar(u) && st[pu].find(v)==st[pu].end()) {
      |                                       ^~