Submission #219070

# Submission time Handle Problem Language Result Execution time Memory
219070 2020-04-03T15:56:19 Z alexandra_udristoiu Making Friends on Joitter is Fun (JOI20_joitter2) C++14
Compilation error
0 ms 0 KB
#include<iostream>
#include<set>
#include<algorithm>
#define DIM 100005
using namespace std;
int n, q, i, j, x, y, r1, r2, ry;
long long sol;
int r[DIM], num[DIM], nv[DIM];
vector<int> v[DIM], vr[DIM];
set<int> s[DIM], sr[DIM];
int rad(int x){
    while(r[x] > 0){
        x = r[x];
    }
    return x;
}
int main(){
    cin>> n >> q;
    for(i = 1; i <= n; i++){
        r[i] = -1;
        num[i] = 1;
        vr[i].push_back(i);
    }
    for(; q; q--){
        cin>> x >> y;
        v[y].push_back(x);
        r1 = rad(x);
        r2 = rad(y);
        if(r1 == r2){
            cout<< sol <<"\n";
            continue;
        }
        if(s[x].find(r2) == s[x].end() ){
            sol += num[r2];
            nv[r2]++;
            s[x].insert(r2);
        }
        sr[r1].insert(r2);
        if(sr[r2].find(r1) == sr[r2].end() ){
            cout<< sol <<"\n";
            continue;
        }
        if(r[r1] > r[r2]){
            swap(r1, r2);
        }
        sol -= num[r1] * 1LL * (num[r1] - 1) + num[r1] * 1LL * nv[r1];
        sol -= num[r2] * 1LL * (num[r2] - 1) / 2 + num[r2] * 1LL * nv[r2];
        for(i = 0; i < vr[r2].size(); i++){
            x = vr[r2][i];
            vr[r1].push_back(x);
            if(s[x].find(r1) != s[x].end() ){
                nv[r1]--;
                s[x].erase(r1);
            }
            for(j = 0; j < v[x].size(); j++){
                y = v[x][j];
                ry = rad(y);
                if(ry == r1){
                    s[y].erase(r2);
                    continue;
                }
                if(s[y].find(r1) == s[y].end() ){
                    s[y].insert(r1);
                    nv[r1]++;
                }
                s[y].erase(r2);
                sr[ry].insert(r1);
                sr[ry].erase(r2);
            }
        }
        set<int> :: iterator it;
        for(it = sr[r2].begin(); it != sr[r2].end(); it++){
            sr[r1].insert(*it);
        }
        r[r1] += r[r2];
        r[r2] = r1;
        num[r1] += num[r2];
        sr[r1].erase(r2);
        sol += num[r1] * 1LL * (num[r1] - 1) + num[r1] * 1LL * nv[r1];
        cout<< sol <<"\n";
    }
}

Compilation message

joitter2.cpp:9:1: error: 'vector' does not name a type; did you mean 'perror'?
 vector<int> v[DIM], vr[DIM];
 ^~~~~~
 perror
joitter2.cpp: In function 'int main()':
joitter2.cpp:22:9: error: 'vr' was not declared in this scope
         vr[i].push_back(i);
         ^~
joitter2.cpp:22:9: note: suggested alternative: 'sr'
         vr[i].push_back(i);
         ^~
         sr
joitter2.cpp:26:9: error: 'v' was not declared in this scope
         v[y].push_back(x);
         ^
joitter2.cpp:48:24: error: 'vr' was not declared in this scope
         for(i = 0; i < vr[r2].size(); i++){
                        ^~
joitter2.cpp:48:24: note: suggested alternative: 'sr'
         for(i = 0; i < vr[r2].size(); i++){
                        ^~
                        sr