Language: C++

#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const int MOD=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};
 
struct UnionFind {
	vector<int> par;
 
	UnionFind(int n) : par(n, -1) { }
	void init(int n) { par.assign(n, -1); }
 
	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}
 
	bool same(int x, int y) {
		return root(x) == root(y);
	}
 
	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}
 
	int size(int x) {
		return -par[root(x)];
	}
};
 
int main(){
	int n,m;
	cin>>n>>m;
	UnionFind tree(n);
	int x[M],y[M];
	//切るのは嫌なのでくっつけていく
	rep(i,0,m)cin>>x[i]>>y[i],x[i]--,y[i]--;
	ll cnt=n*(n-1)/2;
	vl ans;
	rep(i,0,m){
		ans.push_back(cnt);
		int a=x[m-1-i],b=y[m-1-i];
		if(tree.same(a,b))continue;
		ll sa=tree.size(a),sb=tree.size(b);
		cnt-=sa*sb;
		tree.merge(a,b);
	}
	reverse(ALL(ans));
	for(auto v:ans)print(v);
}
 
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const int MOD=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }
	void init(int n) { par.assign(n, -1); }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

int main(){
	 n,m;
	cin>>n>>m;
	UnionFind tree(n);
	int x[M],y[M];
	//切るのは嫌なのでくっつけていく
	rep(i,0,m)cin>>x[i]>>y[i],x[i]--,y[i]--;
	ll cnt=n*(n-1)/2;
	vl ans;
	rep(i,0,m){
		ans.push_back(cnt);
		int a=x[m-1-i],b=y[m-1-i];
		if(tree.same(a,b))continue;
		ll sa=tree.size(a),sb=tree.size(b);
		cnt-=sa*sb;
		tree.merge(a,b);
	}
	reverse(ALL(ans));
	for(auto v:ans)print(v);
}

提出情報
提出日時	2019-08-04 12:07:19
問題	D - Decayed Bridges
ユーザ	Engelcat 
言語	C++14 (GCC 5.4.1)
得点	0
コード長	1492 Byte
結果	
実行時間	208 ms
メモリ	3444 KB
テストケース
セット名	得点 / 配点	テストケース
All

Compiler output:
a.cc:138:22: error: invalid digit "8" in octal constant
  138 | 提出日時        2019-08-04 12:07:19
      |                      ^~
a.cc:141:20: error: too many decimal points in number
  141 | 言語    C++14 (GCC 5.4.1)
      |                    ^~~~~
a.cc:80:11: error: redefinition of 'const int M'
   80 | const int M=100111;
      |           ^
a.cc:12:11: note: 'const int M' previously defined here
   12 | const int M=100111;
      |           ^
a.cc:81:11: error: redefinition of 'const int inf'
   81 | const int inf=1000000007;
      |           ^~~
a.cc:13:11: note: 'const int inf' previously defined here
   13 | const int inf=1000000007;
      |           ^~~
a.cc:82:11: error: redefinition of 'const int MOD'
   82 | const int MOD=1000000007;
      |           ^~~
a.cc:14:11: note: 'const int MOD' previously defined here
   14 | const int MOD=1000000007;
      |           ^~~
a.cc:83:17: error: redefinition of 'const long long int INF'
   83 | const long long INF=1000000000000000007;
      |                 ^~~
a.cc:15:17: note: 'const long long int INF' previously defined here
   15 | const long long INF=1000000000000000007;
      |                 ^~~
a.cc:84:5: error: redefinition of 'int dx [4]'
   84 | int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
      |     ^~
a.cc:16:5: note: 'int dx [4]' previously defined here
   16 | int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
      |     ^~
a.cc:84:22: error: redefinition of 'int dy [4]'
   84 | int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
      |                      ^~
a.cc:16:22: note: 'int dy [4]' previously defined here
   16 | int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
      |                      ^~
a.cc:85:5: error: redefinition of 'int ddx [8]'
   85 | int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};
      |     ^~~
a.cc:17:5: note: 'int ddx [8]' previously defined here
   17 | int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};
      |     ^~~
a.cc:85:33: error: redefinition of 'int ddy [8]'
   85 | int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};
      |                                 ^~~
a.cc:17:33: note: 'int ddy [8]' previously defined here
   17 | int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};
      |                                 ^~~
a.cc:87:8: error: redefinition of 'struct UnionFind'
   87 | struct UnionFind {
      |        ^~~~~~~~~
a.cc:19:8: note: previous definition of 'struct UnionFind'
   19 | struct UnionFind {
      |        ^~~~~~~~~
a.cc:116:5: error: redefinition of 'int main()'
  116 | int main(){
      |     ^~~~
a.cc:48:5: note: 'int main()' previously defined here
   48 | int main(){
      |     ^~~~
a.cc: In function 'int main()':
a.cc:117:10: error: 'n' was not declared in this scope; did you mean 'yn'?
  117 |          n,m;
      |          ^
      |          yn
a.cc:117:12: error: 'm' was not declared in this scope
  117 |          n,m;
      |            ^
a.cc:128:32: error: 'b' was not declared in this scope
  128 |                 if(tree.same(a,b))continue;
      |                                ^
a.cc:129:49: error: 'b' was not declared in this scope; did you mean 'sb'?
  129 |                 ll sa=tree.size(a),sb=tree.size(b);
      |                                                 ^
      |                                                 sb
a.cc: At global scope:
a.cc:137:1: error: '\U000063d0\U000051fa\U000060c5\U00005831' does not name a type
  137 | 提出情報
      | ^~~~~~~~