Submission #2122244
Source Code Expand
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#define rank haaaaaaaa
using namespace std;
vector<int> v1;
vector<int> v2;
struct ha
{
int from;
int to;
}e[100005];
struct haa
{
int L;
int R;
vector<int> set;
}q[105];
int L[100005],R[100005],need[100005];
int f[100005],rank[100005];
int ans[100005];
int cnt;
int n,m,Q;
inline int find(int k)
{
return f[k]==k?k:f[k]=find(f[k]);
}
inline void join(int x,int y)
{
x=find(x);
y=find(y);
if(x==y) return;
f[x]=y;
rank[y]+=rank[x];
//rank[x]=0;
}
inline int co(int u,int v)
{
u=find(u);
v=find(v);
int tot=rank[u];
if(u==v)
tot=rank[u];
else
tot=rank[u]+rank[v];
return tot;
}
int main()
{
scanf("%d%d",&n,&m);
register int a,b,c,d;
for(a=1;a<=n;a++)
f[a]=a,rank[a]=1;
for(a=1;a<=m;a++)
{
scanf("%d%d",&b,&c);
e[a].from=b;
e[a].to=c;
}
scanf("%d",&Q);
q[1].L=0;
q[1].R=m;
for(a=1;a<=Q;a++)
{
scanf("%d%d%d",&L[a],&R[a],&need[a]);
q[1].set.push_back(a);
}
int head=1,tail=2;
int cur=0;
while(head<tail)
{
haa tmp=q[head++];
int l=tmp.L,r=tmp.R;
if(r-l==1)
{
for(a=0;a<tmp.set.size();a++)
ans[tmp.set[a]]=r;
continue;
}
v1.clear();
v2.clear();
int mid=(l+r)>>1;
if(cur>mid)
{
for(b=1;b<=n;b++)
f[b]=b,rank[b]=1;
cur=0;
}
while(cur<mid)
{
cur++;
int u=e[cur].from;
int v=e[cur].to;
join(u,v);
}
for(a=0;a<tmp.set.size();a++)
{
int k=tmp.set[a];
int x=L[k];
int y=R[k];
if(need[k]>co(x,y))
v2.push_back(k);
else
v1.push_back(k);
}
if(v1.size())
{
q[tail].L=l;
q[tail].R=mid;
q[tail].set.clear();
q[tail].set=v1;
tail++;
}
if(v2.size())
{
q[tail].L=mid;
q[tail].R=r;
q[tail].set.clear();
q[tail].set=v2;
tail++;
}
}
for(a=1;a<=Q;a++)
printf("%d\n",ans[a]);
return 0;
}
/*
5 6
2 3
4 5
1 2
1 3
1 4
1 5
6
2 4 3
2 4 4
2 4 5
1 3 3
1 3 4
1 3 5
*/
Submission Info
Submission Time |
|
Task |
D - Stamp Rally |
User |
longgod |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2057 Byte |
Status |
RE |
Exec Time |
179 ms |
Memory |
7024 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:51: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:57:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&b,&c);
^
./Main.cpp:61:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&Q);
^
./Main.cpp:66:39: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&L[a],&R[a],&need[a]);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 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 |
256 KB |
1_00.txt |
RE |
146 ms |
6512 KB |
1_01.txt |
RE |
158 ms |
6384 KB |
1_02.txt |
RE |
148 ms |
6256 KB |
1_03.txt |
RE |
158 ms |
6256 KB |
1_04.txt |
RE |
150 ms |
6128 KB |
1_05.txt |
RE |
158 ms |
6128 KB |
1_06.txt |
RE |
150 ms |
6128 KB |
1_07.txt |
RE |
158 ms |
6128 KB |
1_08.txt |
RE |
151 ms |
6000 KB |
1_09.txt |
RE |
159 ms |
6000 KB |
1_10.txt |
RE |
152 ms |
6000 KB |
1_11.txt |
RE |
161 ms |
6000 KB |
1_12.txt |
RE |
157 ms |
6000 KB |
1_13.txt |
RE |
161 ms |
6000 KB |
1_14.txt |
RE |
157 ms |
6640 KB |
1_15.txt |
RE |
157 ms |
6640 KB |
1_16.txt |
RE |
170 ms |
7024 KB |
1_17.txt |
RE |
174 ms |
6384 KB |
1_18.txt |
RE |
176 ms |
6384 KB |
1_19.txt |
RE |
170 ms |
6768 KB |
1_20.txt |
RE |
170 ms |
6256 KB |
1_21.txt |
RE |
170 ms |
6512 KB |
1_22.txt |
RE |
174 ms |
6256 KB |
1_23.txt |
RE |
173 ms |
6384 KB |
1_24.txt |
RE |
177 ms |
6256 KB |
1_25.txt |
RE |
175 ms |
6384 KB |
1_26.txt |
RE |
171 ms |
6384 KB |
1_27.txt |
RE |
177 ms |
6384 KB |
1_28.txt |
RE |
172 ms |
6384 KB |
1_29.txt |
RE |
179 ms |
6256 KB |
1_30.txt |
RE |
174 ms |
6384 KB |
1_31.txt |
RE |
172 ms |
6256 KB |