Submission #10472235


Source Code Expand

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
struct UnionFind {
	using T = int;
	const T def = 0;
	T f(T a, T b) { return a + b; }
	//==========================================
    vector<int> par; 
	vector<T> value;
    UnionFind() {}
    UnionFind(int NV) { init(NV); }
	void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); value.resize(NV, 1); }
    void reset() { rep(i, 0, par.size()) par[i] = i; }
	int operator[](int x) {
		if (par[x] == x) return x;
		else {
			int res = operator[](par[x]);
			if (res != par[x]) {
				value[res] = f(value[res], value[par[x]]);
				value[par[x]] = def;
			}
			return par[x] = res;
		}
	}
	// uf(x,y)->y
    void operator()(int x, int y) {
		x = operator[](x); y = operator[](y); 
		if (x != y) {
			value[y] += value[par[x]];
			value[par[x]] = def;
			par[x] = y;
		}
	}
	T getValues(int x) { return value[operator[](x)]; };
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, M, K, A[101010], B[101010], C[101010], D[101010];
int ans[101010];
set<int> friends[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> K;
	rep(i, 0, M) cin >> A[i] >> B[i], A[i]--, B[i]--;
	rep(i, 0, K) cin >> C[i] >> D[i], C[i]--, D[i]--;

	UnionFind uf(N);
	rep(i, 0, M) uf(A[i], B[i]);

	rep(i, 0, N) ans[i] = uf.getValues(i) - 1;
	rep(i, 0, M) {
		ans[A[i]]--;
		ans[B[i]]--;
		friends[A[i]].insert(B[i]);
		friends[B[i]].insert(A[i]);
	}
	rep(i, 0, K) if (!friends[C[i]].count(D[i]) && uf[C[i]] == uf[D[i]]) {
		ans[C[i]]--;
		ans[D[i]]--;
	}

	rep(i, 0, N) {
		if(i) printf(" ");
		printf("%d", ans[i]);
	}
	printf("\n");
}





Submission Info

Submission Time
Task D - Friend Suggestions
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2920 Byte
Status AC
Exec Time 119 ms
Memory 18168 KiB

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 3 ms 6400 KiB
00-sample-01 AC 3 ms 6400 KiB
00-sample-02 AC 3 ms 6400 KiB
01-handmade-00 AC 3 ms 6400 KiB
01-handmade-01 AC 3 ms 6400 KiB
01-handmade-02 AC 45 ms 14588 KiB
01-handmade-03 AC 19 ms 7160 KiB
01-handmade-04 AC 79 ms 17656 KiB
01-handmade-05 AC 94 ms 18168 KiB
01-handmade-06 AC 119 ms 17272 KiB
02-small-00 AC 3 ms 6400 KiB
02-small-01 AC 3 ms 6400 KiB
02-small-02 AC 3 ms 6400 KiB
02-small-03 AC 3 ms 6400 KiB
02-small-04 AC 3 ms 6400 KiB
02-small-05 AC 3 ms 6400 KiB
02-small-06 AC 3 ms 6400 KiB
02-small-07 AC 3 ms 6400 KiB
02-small-08 AC 3 ms 6400 KiB
02-small-09 AC 3 ms 6400 KiB
03-large-00 AC 54 ms 12668 KiB
03-large-01 AC 68 ms 15992 KiB
03-large-02 AC 62 ms 15228 KiB
03-large-03 AC 54 ms 13688 KiB
03-large-04 AC 55 ms 13688 KiB
03-large-05 AC 54 ms 13688 KiB
03-large-06 AC 50 ms 12284 KiB
03-large-07 AC 66 ms 15100 KiB
03-large-08 AC 70 ms 16248 KiB
03-large-09 AC 84 ms 17656 KiB