ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1671. Anansi's Cobweb

Help!WA#11
Posted by miao22 23 Jun 2019 17:08
#include<bits/stdc++.h>
using namespace std;
int n,m,q,a[100003],b[100003],c[100003];
vector<pair<int,int> >v;
vector<int>g[100003];
bool vis[100003];
int qq[100003];
map<int,int>mp;
void dfs(int x,int cc){
    vis[x]=1;
    for(int i=0;i<g[x].size();i++)
        if(!vis[g[x][i]])
            dfs(g[x][i],cc);
    qq[x]=cc;
}
int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++)
        cin>>a[i]>>b[i],
        a[i]--,
        b[i]--;
    cin>>q;
    for(int i=0;i<q;i++)cin>>c[i],c[i]--,v.push_back(make_pair(a[c[i]],b[c[i]])),a[c[i]]=b[c[i]]=-1;
    reverse(c,c+n);reverse(v.begin(),v.end());
    for(int i=0;i<m;i++)
        if(a[i]!=-1)
            g[a[i]].push_back(b[i]),
            g[b[i]].push_back(a[i]);
    int cnt=0;
    for(int i=0;i<n;i++)
        if(!vis[i])
            mp[cnt]=cnt,
            dfs(i,cnt++);
    vector<int>ans;
    for(int i=0;i<q;i++){
        ans.push_back(cnt);
        if(mp[qq[v[i].first]]!=mp[qq[v[i].second]])
            mp[qq[v[i].first]]=mp[qq[v[i].second]],
            qq[v[i].first]=qq[v[i].second],
            cnt--;
    }
    reverse(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<' ';
}
Re: Help!WA#11
Posted by miao22 23 Jun 2019 17:09
are there any test?