Submission #3223500
Source Code Expand
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
#define INF ((1ll<<60)-233)
#define sqr(x) ((x)*(x))
#define debug puts("wzpkking")
using namespace std;
const int N=100005;
int n,m,fa[N],sz[N];
void init(){
For(i,1,n) fa[i]=i,sz[i]=1;
}
int get(int x){
return x==fa[x]?x:fa[x]=get(fa[x]);
}
void merge(int x,int y){
x=get(x); y=get(y);
if (x!=y) sz[fa[y]=x]+=sz[y];
}
struct node{
int l,r,Q,*id;
}s[N<<5];
int h,t;
void insert(int l,int r,int *id,int Q){
s[++t]=(node){l,r,Q,id};
}
int calc(int x,int y){
x=get(x),y=get(y);
return sz[x]+(x==y?0:sz[y]);
}
struct edge{
int x,y;
}e[N];
struct que{
int x,y,z,ans;
}q[N];
int cur,Q;
int tl[N],tr[N];
void solve(node wzp){
int l=wzp.l,r=wzp.r,*id=wzp.id,Q=wzp.Q;
if (l>r||!Q) return;
int mid=(l+r)/2;
if (cur>mid) init(),cur=0;
for (;cur<mid;cur++,merge(e[cur].x,e[cur].y));
int cl=0,cr=0;
For(i,1,Q){
int ID=id[i],res=calc(q[ID].x,q[ID].y);
if (res>=q[ID].z) tl[++cl]=ID,q[ID].ans=min(q[ID].ans,mid);
else tr[++cr]=ID;
}
For(i,1,cl) id[i]=tl[i];
For(i,1,cr) id[i+cl]=tr[i];
insert(l,mid-1,id,cl);
insert(mid+1,r,id+cl,cr);
}
void BFS(int l,int r,int *id,int Q){
init(); insert(l,r,id,Q);
for (;h<t;solve(s[++h]));
}
int id[N];
int main(){
scanf("%d%d",&n,&m);
For(i,1,m) scanf("%d%d",&e[i].x,&e[i].y);
scanf("%d",&Q);
For(i,1,Q){
scanf("%d%d%d",&q[i].x,&q[i].y,&q[i].z);
id[i]=i; q[i].ans=m;
}
BFS(1,m,id,Q);
For(i,1,Q) printf("%d\n",q[i].ans);
}
Submission Info
Submission Time |
|
Task |
D - Stamp Rally |
User |
zhouyuyang |
Language |
C++14 (GCC 5.4.1) |
Score |
1000 |
Code Size |
2200 Byte |
Status |
AC |
Exec Time |
178 ms |
Memory |
9472 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:88:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
^
./Main.cpp:89:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
For(i,1,m) scanf("%d%d",&e[i].x,&e[i].y);
^
./Main.cpp:90:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&Q);
^
./Main.cpp:92:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&q[i].x,&q[i].y,&q[i].z);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1000 / 1000 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_00.txt |
All |
0_00.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt |
Case Name |
Status |
Exec Time |
Memory |
0_00.txt |
AC |
1 ms |
2304 KB |
1_00.txt |
AC |
83 ms |
9344 KB |
1_01.txt |
AC |
102 ms |
9472 KB |
1_02.txt |
AC |
84 ms |
9344 KB |
1_03.txt |
AC |
103 ms |
9472 KB |
1_04.txt |
AC |
84 ms |
9344 KB |
1_05.txt |
AC |
104 ms |
9472 KB |
1_06.txt |
AC |
85 ms |
9344 KB |
1_07.txt |
AC |
105 ms |
9472 KB |
1_08.txt |
AC |
87 ms |
9344 KB |
1_09.txt |
AC |
107 ms |
9472 KB |
1_10.txt |
AC |
92 ms |
9344 KB |
1_11.txt |
AC |
111 ms |
9472 KB |
1_12.txt |
AC |
101 ms |
9344 KB |
1_13.txt |
AC |
116 ms |
9472 KB |
1_14.txt |
AC |
88 ms |
7552 KB |
1_15.txt |
AC |
99 ms |
7552 KB |
1_16.txt |
AC |
153 ms |
5504 KB |
1_17.txt |
AC |
172 ms |
7552 KB |
1_18.txt |
AC |
171 ms |
7552 KB |
1_19.txt |
AC |
156 ms |
5504 KB |
1_20.txt |
AC |
163 ms |
7424 KB |
1_21.txt |
AC |
161 ms |
5504 KB |
1_22.txt |
AC |
170 ms |
7552 KB |
1_23.txt |
AC |
173 ms |
7552 KB |
1_24.txt |
AC |
178 ms |
7424 KB |
1_25.txt |
AC |
167 ms |
7552 KB |
1_26.txt |
AC |
160 ms |
7552 KB |
1_27.txt |
AC |
168 ms |
7552 KB |
1_28.txt |
AC |
163 ms |
7552 KB |
1_29.txt |
AC |
176 ms |
7424 KB |
1_30.txt |
AC |
170 ms |
7552 KB |
1_31.txt |
AC |
162 ms |
7424 KB |