Submission #57176

# Submission time Handle Problem Language Result Execution time Memory
57176 2018-07-14T08:17:28 Z red1108 None (KOI16_tree) C++17
0 / 100
3 ms 376 KB
#include <stdio.h>
#include <stack>
using namespace std;
stack<bool> ans;
int bumo[200010], input[500010][3], par[200010];
int n, q;
int pfind(int x)
{
    if(par[x]==x) return x;
    return par[x]=pfind(par[x]);
}
void uni(int a, int b)
{
    par[pfind(a)]=pfind(b);
}
int main()
{
    int i, a, b;
    scanf("%d %d", &n, &q);
    par[1]=1;
    for(i=2;i<=n;i++)
    {
        par[i]=i;
        scanf("%d", &bumo[i]);
    }
    for(i=1;i<=q+n-1;i++)
    {
        scanf("%d %d", &input[i][0], &input[i][1]);
        if(input[i][0]==1)
        {
            scanf("%d", &input[i][2]);
        }
    }
    for(i=q+n-1;i>=1;i--)
    {
        if(input[i][0]==1)
        {
            if(pfind(input[i][1])==pfind(input[i][2]))
            {
                ans.push(1);
            }
            else ans.push(0);
        }
        else
        {
            uni(input[i][1],bumo[input[i][1]]);
        }
    }
    while(!ans.empty())
    {
        printf("%s\n",ans.top()==1?"YES":"NO");
        ans.pop();
    }
}

Compilation message

tree.cpp: In function 'int main()':
tree.cpp:18:12: warning: unused variable 'a' [-Wunused-variable]
     int i, a, b;
            ^
tree.cpp:18:15: warning: unused variable 'b' [-Wunused-variable]
     int i, a, b;
               ^
tree.cpp:19: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:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &bumo[i]);
         ~~~~~^~~~~~~~~~~~~~~~
tree.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &input[i][0], &input[i][1]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tree.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &input[i][2]);
             ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -