Submission #10450339


Source Code Expand

Copy
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
struct unionfind{
    vector<int> par, sz;
    unionfind() {}
    unionfind(int n):par(n), sz(n, 1){
        for(int i=0; i<n; i++) par[i]=i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x, int y){
        x=find(x); y=find(y);
        if(x==y) return;
        if(sz[x]>sz[y]) swap(x, y);
        par[x]=y;
        sz[y]+=sz[x];
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sz[find(x)];
    }
};
int main()
{
    int n, m, k;
	cin>>n>>m>>k;
	int a[100010], b[100010], c[100010], d[100010];
	unionfind uf(n);
	for(int i=0; i<m; i++){
		cin>>a[i]>>b[i];
		a[i]--; b[i]--;
		if(a[i]>b[i]) swap(a[i], b[i]);
		uf.unite(a[i], b[i]);
	}
	for(int i=0; i<k; i++){
		cin>>c[i]>>d[i];
		c[i]--; d[i]--;
		if(c[i]>d[i]) swap(c[i], d[i]);
	}
	vector<int> v;
	for(int i=0; i<n; i++){
		v.push_back(uf.find(i));
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	int ans[100010]={};
	for(auto x:v){
		ll cnt=uf.size(x);
		ans[x]+=cnt;
	}
	int myon[100010]={};
	for(int i=0; i<k; i++){
		if(uf.same(c[i], d[i])){
			myon[c[i]]++; myon[d[i]]++;
		}
	}
	for(int i=0; i<m; i++){
		myon[a[i]]++; myon[b[i]]++;
	}
	for(int i=0; i<n; i++) cout<<ans[uf.find(i)]-myon[i]-1<<" ";
	cout<<endl;
	return 0;
}

Submission Info

Submission Time
Task D - Friend Suggestions
User chocorusk
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1981 Byte
Status AC
Exec Time 131 ms
Memory 4472 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 30
Set Name Test Cases
Sample 00-sample-00, 00-sample-01, 00-sample-02
All 00-sample-00, 00-sample-01, 00-sample-02, 01-handmade-00, 01-handmade-01, 01-handmade-02, 01-handmade-03, 01-handmade-04, 01-handmade-05, 01-handmade-06, 02-small-00, 02-small-01, 02-small-02, 02-small-03, 02-small-04, 02-small-05, 02-small-06, 02-small-07, 02-small-08, 02-small-09, 03-large-00, 03-large-01, 03-large-02, 03-large-03, 03-large-04, 03-large-05, 03-large-06, 03-large-07, 03-large-08, 03-large-09
Case Name Status Exec Time Memory
00-sample-00 AC 2 ms 1024 KB
00-sample-01 AC 2 ms 1024 KB
00-sample-02 AC 2 ms 1024 KB
01-handmade-00 AC 2 ms 2432 KB
01-handmade-01 AC 2 ms 1024 KB
01-handmade-02 AC 52 ms 2812 KB
01-handmade-03 AC 45 ms 2552 KB
01-handmade-04 AC 128 ms 4472 KB
01-handmade-05 AC 126 ms 4472 KB
01-handmade-06 AC 131 ms 4088 KB
02-small-00 AC 2 ms 1024 KB
02-small-01 AC 2 ms 1024 KB
02-small-02 AC 2 ms 1024 KB
02-small-03 AC 2 ms 1024 KB
02-small-04 AC 2 ms 1024 KB
02-small-05 AC 2 ms 1024 KB
02-small-06 AC 2 ms 1024 KB
02-small-07 AC 2 ms 1024 KB
02-small-08 AC 2 ms 1024 KB
02-small-09 AC 2 ms 1024 KB
03-large-00 AC 95 ms 3324 KB
03-large-01 AC 104 ms 3704 KB
03-large-02 AC 92 ms 3324 KB
03-large-03 AC 92 ms 4088 KB
03-large-04 AC 89 ms 3320 KB
03-large-05 AC 88 ms 3448 KB
03-large-06 AC 87 ms 3196 KB
03-large-07 AC 101 ms 3452 KB
03-large-08 AC 113 ms 4088 KB
03-large-09 AC 130 ms 4344 KB