# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
57808 |
2018-07-16T08:56:56 Z |
red1108 |
None (KOI16_tree) |
C++17 |
|
860 ms |
66520 KB |
#include <stdio.h>
#include <vector>
using namespace std;
int n,q;
vector<int> tree[200010];
int seg[800010],par[200010],cnt=0,si=1,color[200010],ccnt=1;
pair<int,int> range[200010];
bool cut[200010];
void dfs(int x)
{
range[x].first=++cnt;
for(auto i:tree[x])
dfs(i);
range[x].second=cnt;
}
void rename(int x,int newc)
{
color[x]=newc;
for(auto i:tree[x])
{
if(!cut[i]) rename(i,newc);
}
}
void gang(int x, int k)
{
x=x+si-1;
int delta=k-seg[x];
while(x)
{
seg[x]+=delta;
x/=2;
}
}
int getsize(int x, int l, int r, int s, int e)
{
if(l>r||e<l||r<s)
return 0;
if(s<=l&&r<=e)
return seg[x];
return getsize(x*2,l,(l+r)/2,s,e)+getsize(x*2+1,(l+r)/2+1,r,s,e);
}
int main()
{
int i,a,b,c,flag;
scanf("%d %d", &n, &q);
while(si<n)
si*=2;
for(i=2; i<=n; i++)
{
scanf("%d", &a);
tree[a].push_back(i);
}
for(i=1;i<=n;i++)
color[i]=1;
par[1]=1;
dfs(1);
for(i=1;i<=n;i++)
{
gang(i,1);
}
for(i=1;i<=q;i++)
{
scanf("%d %d %d", &a, &b, &c);
flag=0;
if(color[a]==color[b])
{
printf("YES\n");
flag=1;
}
else
printf("NO\n");
if(c==0)
continue;
if(!flag)
a=b;
if(cut[a]==1)
continue;
cut[a]=1;
gang(range[a].first,(-1)*getsize(1,1,si,range[a].first+1,range[a].second));
int sip, sia;
sip=getsize(1,1,si,range[par[color[a]]].first+1,range[par[color[a]]].second)+1;
sia=getsize(1,1,si,range[a].first+1,range[a].second)+1;
if(sip<=sia)
{
par[ccnt+1]=par[color[a]];
int tmp=color[a];
rename(par[color[a]],++ccnt);
par[tmp]=a;
}
else
{
rename(a,++ccnt);
par[ccnt]=a;
}
}
}
Compilation message
tree.cpp: In function 'int main()':
tree.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~~
tree.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a);
~~~~~^~~~~~~~~~
tree.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &a, &b, &c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
10 ms |
5300 KB |
Output is correct |
4 |
Correct |
8 ms |
5308 KB |
Output is correct |
5 |
Correct |
9 ms |
5340 KB |
Output is correct |
6 |
Correct |
8 ms |
5428 KB |
Output is correct |
7 |
Correct |
8 ms |
5440 KB |
Output is correct |
8 |
Correct |
9 ms |
5516 KB |
Output is correct |
9 |
Correct |
10 ms |
5596 KB |
Output is correct |
10 |
Correct |
8 ms |
5596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
10 ms |
5300 KB |
Output is correct |
4 |
Correct |
8 ms |
5308 KB |
Output is correct |
5 |
Correct |
9 ms |
5340 KB |
Output is correct |
6 |
Correct |
8 ms |
5428 KB |
Output is correct |
7 |
Correct |
8 ms |
5440 KB |
Output is correct |
8 |
Correct |
9 ms |
5516 KB |
Output is correct |
9 |
Correct |
10 ms |
5596 KB |
Output is correct |
10 |
Correct |
8 ms |
5596 KB |
Output is correct |
11 |
Correct |
9 ms |
5668 KB |
Output is correct |
12 |
Correct |
8 ms |
5684 KB |
Output is correct |
13 |
Correct |
7 ms |
5700 KB |
Output is correct |
14 |
Correct |
9 ms |
5716 KB |
Output is correct |
15 |
Correct |
9 ms |
5732 KB |
Output is correct |
16 |
Correct |
9 ms |
5748 KB |
Output is correct |
17 |
Correct |
7 ms |
5764 KB |
Output is correct |
18 |
Correct |
8 ms |
5780 KB |
Output is correct |
19 |
Correct |
9 ms |
5796 KB |
Output is correct |
20 |
Correct |
7 ms |
5796 KB |
Output is correct |
21 |
Correct |
8 ms |
5828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
10 ms |
5300 KB |
Output is correct |
4 |
Correct |
8 ms |
5308 KB |
Output is correct |
5 |
Correct |
9 ms |
5340 KB |
Output is correct |
6 |
Correct |
8 ms |
5428 KB |
Output is correct |
7 |
Correct |
8 ms |
5440 KB |
Output is correct |
8 |
Correct |
9 ms |
5516 KB |
Output is correct |
9 |
Correct |
10 ms |
5596 KB |
Output is correct |
10 |
Correct |
8 ms |
5596 KB |
Output is correct |
11 |
Correct |
9 ms |
5668 KB |
Output is correct |
12 |
Correct |
8 ms |
5684 KB |
Output is correct |
13 |
Correct |
7 ms |
5700 KB |
Output is correct |
14 |
Correct |
9 ms |
5716 KB |
Output is correct |
15 |
Correct |
9 ms |
5732 KB |
Output is correct |
16 |
Correct |
9 ms |
5748 KB |
Output is correct |
17 |
Correct |
7 ms |
5764 KB |
Output is correct |
18 |
Correct |
8 ms |
5780 KB |
Output is correct |
19 |
Correct |
9 ms |
5796 KB |
Output is correct |
20 |
Correct |
7 ms |
5796 KB |
Output is correct |
21 |
Correct |
8 ms |
5828 KB |
Output is correct |
22 |
Correct |
91 ms |
8724 KB |
Output is correct |
23 |
Correct |
88 ms |
10876 KB |
Output is correct |
24 |
Correct |
108 ms |
13100 KB |
Output is correct |
25 |
Correct |
100 ms |
15276 KB |
Output is correct |
26 |
Correct |
103 ms |
17524 KB |
Output is correct |
27 |
Correct |
113 ms |
19880 KB |
Output is correct |
28 |
Correct |
86 ms |
22080 KB |
Output is correct |
29 |
Correct |
129 ms |
24228 KB |
Output is correct |
30 |
Correct |
81 ms |
26540 KB |
Output is correct |
31 |
Correct |
102 ms |
28868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
10 ms |
5300 KB |
Output is correct |
4 |
Correct |
8 ms |
5308 KB |
Output is correct |
5 |
Correct |
9 ms |
5340 KB |
Output is correct |
6 |
Correct |
8 ms |
5428 KB |
Output is correct |
7 |
Correct |
8 ms |
5440 KB |
Output is correct |
8 |
Correct |
9 ms |
5516 KB |
Output is correct |
9 |
Correct |
10 ms |
5596 KB |
Output is correct |
10 |
Correct |
8 ms |
5596 KB |
Output is correct |
11 |
Correct |
854 ms |
49400 KB |
Output is correct |
12 |
Correct |
813 ms |
53796 KB |
Output is correct |
13 |
Correct |
860 ms |
58064 KB |
Output is correct |
14 |
Correct |
822 ms |
62188 KB |
Output is correct |
15 |
Runtime error |
796 ms |
66520 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5112 KB |
Output is correct |
2 |
Correct |
9 ms |
5112 KB |
Output is correct |
3 |
Correct |
10 ms |
5300 KB |
Output is correct |
4 |
Correct |
8 ms |
5308 KB |
Output is correct |
5 |
Correct |
9 ms |
5340 KB |
Output is correct |
6 |
Correct |
8 ms |
5428 KB |
Output is correct |
7 |
Correct |
8 ms |
5440 KB |
Output is correct |
8 |
Correct |
9 ms |
5516 KB |
Output is correct |
9 |
Correct |
10 ms |
5596 KB |
Output is correct |
10 |
Correct |
8 ms |
5596 KB |
Output is correct |
11 |
Correct |
9 ms |
5668 KB |
Output is correct |
12 |
Correct |
8 ms |
5684 KB |
Output is correct |
13 |
Correct |
7 ms |
5700 KB |
Output is correct |
14 |
Correct |
9 ms |
5716 KB |
Output is correct |
15 |
Correct |
9 ms |
5732 KB |
Output is correct |
16 |
Correct |
9 ms |
5748 KB |
Output is correct |
17 |
Correct |
7 ms |
5764 KB |
Output is correct |
18 |
Correct |
8 ms |
5780 KB |
Output is correct |
19 |
Correct |
9 ms |
5796 KB |
Output is correct |
20 |
Correct |
7 ms |
5796 KB |
Output is correct |
21 |
Correct |
8 ms |
5828 KB |
Output is correct |
22 |
Correct |
91 ms |
8724 KB |
Output is correct |
23 |
Correct |
88 ms |
10876 KB |
Output is correct |
24 |
Correct |
108 ms |
13100 KB |
Output is correct |
25 |
Correct |
100 ms |
15276 KB |
Output is correct |
26 |
Correct |
103 ms |
17524 KB |
Output is correct |
27 |
Correct |
113 ms |
19880 KB |
Output is correct |
28 |
Correct |
86 ms |
22080 KB |
Output is correct |
29 |
Correct |
129 ms |
24228 KB |
Output is correct |
30 |
Correct |
81 ms |
26540 KB |
Output is correct |
31 |
Correct |
102 ms |
28868 KB |
Output is correct |
32 |
Correct |
854 ms |
49400 KB |
Output is correct |
33 |
Correct |
813 ms |
53796 KB |
Output is correct |
34 |
Correct |
860 ms |
58064 KB |
Output is correct |
35 |
Correct |
822 ms |
62188 KB |
Output is correct |
36 |
Runtime error |
796 ms |
66520 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
37 |
Halted |
0 ms |
0 KB |
- |