Submission #1069282
Source Code Expand
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i = (j);i < (int)(k);i++)
using namespace std;
const int N = 200003;
int st[N],st1[N],st2[N];
vector<vector<int> > sr(N);
vector<vector<int> > sr1(N);
vector<vector<int> > sr2(N);
int findst(int x){
if(x == st[x]) return x;
else return st[x] = findst(st[x]);
}
void unionst(int x,int y){
int fx = findst(x);
int fy = findst(y);
st[fy] = fx;
}
int findst1(int x){
if(x == st1[x]) return x;
return st1[x] = findst1(st1[x]);
}
void unionst1(int x,int y){
int fx = findst1(x);
int fy = findst1(y);
st1[fy] = fx;
}
int main()
{
int n,k,l,x,y;
scanf("%d%d%d",&n,&k,&l);
rep(i,1,n+1) st[i] = st1[i] = i ;
rep(i,0,k){
scanf("%d %d",&x,&y);
unionst(x,y);
}
rep(i,0,l){
scanf("%d %d",&x,&y);
unionst1(x,y);
}
rep(i,1,n+1) st[i] = findst(st[i]),st1[i] = findst1(st1[i]);
rep(i,1,n+1) sr[st[i]].push_back(i);
rep(i,1,n+1) {
sr1[i].assign(sr[st[i]].begin(),sr[st[i]].end());
}
sr.clear();sr.resize(n+1);
rep(i,1,n+1) sr[st1[i]].push_back(i);
rep(i,1,n+1) {
sr2[i].assign(sr[st1[i]].begin(),sr[st1[i]].end());
}
rep(i,1,n+1){
// printf("%d %d\n",sr1[i].size(),sr2[i].size());
sr1[i].insert(sr1[i].end(),sr2[i].begin(),sr2[i].end());
sort(sr1[i].begin(),sr1[i].end());
int l = sr1[i].size();
int l1 = unique(sr1[i].begin(),sr1[i].end()) - sr1[i].begin();
// for(int j = 0;j < sr2[i].size();j++) printf("%d\n",sr2[i][j]);
printf("%d ",l-l1);
}
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Connectivity |
User |
vjudge1 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1609 Byte |
Status |
TLE |
Exec Time |
2275 ms |
Memory |
824448 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:31:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&n,&k,&l);
^
./Main.cpp:34:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&x,&y);
^
./Main.cpp:38:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&x,&y);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
subtask0_0.txt, subtask0_1.txt, subtask0_2.txt |
All |
subtask0_0.txt, subtask0_1.txt, subtask0_2.txt, subtask1_0.txt, subtask1_1.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_2.txt, subtask1_3.txt, subtask1_4.txt, subtask1_5.txt, subtask1_6.txt, subtask1_7.txt, subtask1_8.txt, subtask1_9.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask0_0.txt |
AC |
21 ms |
14336 KB |
subtask0_1.txt |
AC |
20 ms |
14336 KB |
subtask0_2.txt |
AC |
21 ms |
14336 KB |
subtask1_0.txt |
AC |
462 ms |
71680 KB |
subtask1_1.txt |
TLE |
2163 ms |
824448 KB |
subtask1_10.txt |
AC |
658 ms |
94592 KB |
subtask1_11.txt |
TLE |
2155 ms |
684416 KB |
subtask1_12.txt |
TLE |
2267 ms |
-2038152 KB |
subtask1_13.txt |
TLE |
2263 ms |
-2037636 KB |
subtask1_14.txt |
AC |
170 ms |
38912 KB |
subtask1_2.txt |
TLE |
2275 ms |
-2029320 KB |
subtask1_3.txt |
TLE |
2261 ms |
-2039432 KB |
subtask1_4.txt |
AC |
168 ms |
38016 KB |
subtask1_5.txt |
AC |
901 ms |
110848 KB |
subtask1_6.txt |
TLE |
2168 ms |
628096 KB |
subtask1_7.txt |
TLE |
2264 ms |
-2036104 KB |
subtask1_8.txt |
TLE |
2262 ms |
-2033288 KB |
subtask1_9.txt |
AC |
173 ms |
41216 KB |