Submission #269227

# Submission time Handle Problem Language Result Execution time Memory
269227 2020-08-17T05:50:33 Z 송준혁(#5099) Making Friends on Joitter is Fun (JOI20_joitter2) C++17
0 / 100
8 ms 9856 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, M;
int P[101010];
LL ans;
set<int> S[101010], T[101010];

int rt(int u){
	if (P[u] < 0) return u;
	return P[u] = rt(P[u]);
}

int main(){
	scanf("%d %d", &N, &M);
	for (int i=1; i<=N; i++) P[i]=-1, S[i].insert(i);
	for (int i=1; i<=M; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		int u=rt(x), v=rt(y);
		if (S[v].find(x) != S[v].end()){
			printf("%lld\n", ans);
			continue;
		}
		if (T[v].find(u) != T[v].end()){
			if (S[u].size() < S[v].size()) swap(u, v);
			ans -= P[u]*(LL)S[v].size() + P[v]*(LL)S[u].size();
			for (int t : S[v]){
				if (S[u].find(t) != S[u].end()) ans += P[u] + P[v];
				else S[u].insert(t);

				T[rt(t)].erase(v);
				T[rt(t)].insert(u);
			}
			S[v].clear();
			P[u] += P[v], P[v]=u;
		}
		else{
			ans -= P[v];
			T[u].insert(v);
			S[v].insert(x);
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Compilation message

joitter2.cpp: In function 'int main()':
joitter2.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%d %d", &N, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~
joitter2.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |   scanf("%d %d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 9856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 9856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 9856 KB Output isn't correct
2 Halted 0 ms 0 KB -