Submission #1225590
Source Code Expand
#include <cstdio>
#include <iostream>
using namespace std;
#define DEBUG(X) cerr<<__LINE__<<" "<<#X<<": "<<X<<endl;
#define sci(x) int x;scanf("%d",&x);
#define scii(x, y) int x,y;scanf("%d%d",&x,&y);
struct UFTree {
int par[1000010]; // 親
int rank[1000010]; // 木の深さ
UFTree(int n){
for(int i=0;i<n;i++){
par[i] = i;
rank[i] = 0;
}
}
int root(int a){
if (par[a] == a) return a;
else return par[a] = root(par[a]);
}
bool unite(int a,int b){
a=root(a);
b=root(b);
if(a==b) return false;
if (rank[a] < rank[b])
par[a] = b;
else {
par[b] = a;
if (rank[a] == rank[b]) rank[a]++;
}
return true;
}
bool same(int a,int b) {
return root(a) == root(b);
}
};
int main() {
scii(N, M)
UFTree tree(N);
for (int i=0;i<M;i++) {
scii(a,b);
tree.unite(a,b);
}
int ans = 0;
for (int j=0;j<N;j++) {
if (tree.par[j]==j) ans++;
}
printf("%d\n",--ans);
}
Submission Info
Submission Time
2017-04-16 15:23:11+0900
Task
B - 道路工事
User
fifth_russian
Language
C++14 (GCC 5.4.1)
Score
100
Code Size
1022 Byte
Status
AC
Exec Time
20 ms
Memory
4352 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:6:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
#define scii(x, y) int x,y;scanf("%d%d",&x,&y);
^
./Main.cpp:41:3: note: in expansion of macro ‘scii’
scii(N, M)
^
./Main.cpp:6:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
#define scii(x, y) int x,y;scanf("%d%d",&x,&y);
^
./Main.cpp:44:5: note: in expansion of macro ‘scii’
scii(a,b);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
100 / 100
Status
Set Name
Test Cases
Sample
sample1.txt, sample2.txt
All
0.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt
Case Name
Status
Exec Time
Memory
0.txt
AC
2 ms
2304 KB
1.txt
AC
2 ms
2304 KB
10.txt
AC
2 ms
2304 KB
11.txt
AC
1 ms
2304 KB
12.txt
AC
2 ms
4352 KB
13.txt
AC
2 ms
2304 KB
14.txt
AC
2 ms
2304 KB
15.txt
AC
15 ms
2304 KB
16.txt
AC
2 ms
2688 KB
17.txt
AC
2 ms
2688 KB
18.txt
AC
2 ms
2688 KB
19.txt
AC
20 ms
2688 KB
2.txt
AC
2 ms
2304 KB
3.txt
AC
2 ms
2304 KB
4.txt
AC
2 ms
2304 KB
5.txt
AC
2 ms
2304 KB
6.txt
AC
2 ms
2304 KB
7.txt
AC
2 ms
2304 KB
8.txt
AC
2 ms
2304 KB
9.txt
AC
2 ms
2304 KB
sample1.txt
AC
1 ms
2304 KB
sample2.txt
AC
2 ms
2304 KB