Submission #1069292
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> > srt(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),srt[st1[i]].push_back(i);
rep(i,1,n+1) {
sr1[i].assign(sr[st[i]].begin(),sr[st[i]].end());
sr2[i].assign(srt[st1[i]].begin(),srt[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 |
1567 Byte |
Status |
TLE |
Exec Time |
2243 ms |
Memory |
887168 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:32: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:35: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:39: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 |
25 ms |
18944 KB |
subtask0_1.txt |
AC |
25 ms |
18944 KB |
subtask0_2.txt |
AC |
25 ms |
18944 KB |
subtask1_0.txt |
AC |
493 ms |
95488 KB |
subtask1_1.txt |
TLE |
2155 ms |
887168 KB |
subtask1_10.txt |
AC |
695 ms |
126080 KB |
subtask1_11.txt |
TLE |
2147 ms |
739456 KB |
subtask1_12.txt |
TLE |
2239 ms |
-1991440 KB |
subtask1_13.txt |
TLE |
2243 ms |
-1991436 KB |
subtask1_14.txt |
AC |
184 ms |
47360 KB |
subtask1_2.txt |
TLE |
2243 ms |
-2010508 KB |
subtask1_3.txt |
TLE |
2239 ms |
-1994640 KB |
subtask1_4.txt |
AC |
182 ms |
46464 KB |
subtask1_5.txt |
AC |
962 ms |
147712 KB |
subtask1_6.txt |
TLE |
2159 ms |
694784 KB |
subtask1_7.txt |
TLE |
2240 ms |
-1985804 KB |
subtask1_8.txt |
TLE |
2238 ms |
-1994000 KB |
subtask1_9.txt |
AC |
189 ms |
50176 KB |