Submission #1358069
Source Code Expand
#include <bits/stdc++.h> using namespace std; int par[100010]; bool c[100010]; int r(int x){ return x==par[x]?x:(par[x]=r(par[x])); } int main(){ int n, m; scanf("%d%d", &n, &m); for(int i=1; i<=n; ++i) par[i]=i; for(int i=1; i<=m; ++i){ int a, b; scanf("%d%d",&a,&b); par[r(a)]=r(b); } int ans=0; for(int i=1; i<=n; ++i) if(!c[r(i)]) c[r(i)]=1, ++ans; printf("%d\n", n-1-ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - 道路工事 |
User | Namnamseo |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 406 Byte |
Status | WA |
Exec Time | 22 ms |
Memory | 768 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:8:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &n, &m); ^ ./Main.cpp:11:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int a, b; scanf("%d%d",&a,&b); ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | WA | 1 ms | 256 KB |
1.txt | WA | 1 ms | 256 KB |
10.txt | WA | 1 ms | 256 KB |
11.txt | WA | 1 ms | 256 KB |
12.txt | WA | 1 ms | 256 KB |
13.txt | WA | 1 ms | 256 KB |
14.txt | WA | 1 ms | 256 KB |
15.txt | WA | 15 ms | 256 KB |
16.txt | WA | 2 ms | 768 KB |
17.txt | WA | 2 ms | 768 KB |
18.txt | WA | 2 ms | 768 KB |
19.txt | WA | 22 ms | 768 KB |
2.txt | WA | 1 ms | 256 KB |
3.txt | WA | 1 ms | 256 KB |
4.txt | WA | 1 ms | 256 KB |
5.txt | AC | 1 ms | 256 KB |
6.txt | AC | 1 ms | 256 KB |
7.txt | AC | 1 ms | 256 KB |
8.txt | WA | 1 ms | 256 KB |
9.txt | WA | 1 ms | 256 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |