QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#447245#33. Cat in a treeYassirSalama0 1ms3740kbC++142.0kb2024-06-18 07:36:442024-06-18 07:36:44

Judging History

你现在查看的是最新测评结果

  • [2024-06-18 07:36:44]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3740kb
  • [2024-06-18 07:36:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define endl "\n"
using ull=unsigned long long;
using ll=long long;
using pii=pair<int,int>;
const int mod=1e9+7;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
template <typename T> istream& operator>>(istream& is, vector<T> &a) {
    copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;}
#ifdef IOI
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int mxn=1e3+600;
vector<int> v[mxn];
int n,D;
int dfs(int node,int d,int par=-1){
    d=(d+D)%D;
    int ans=0;
    for(auto x:v[node]){
        if(x==par) continue;
        int k=0;
        bool c=false;
        for(auto y:v[node]){
            if(y==par) continue;
            if(x^y){
                c=true;
                int t=dfs(y,D-(d+1),node)+dfs(x,d-1,node);
                k=max(k,t);
            }
        }
        if(!c){
            k=max(k,dfs(x,d-1,node));
        }
        ans=max(ans,(d==0)+k);
    }
    return max(ans,(int)(d==0));
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>D;
for(int i=1;i<n;i++){
    int a;
    cin>>a;
    v[a].pb(i);
    v[i].pb(a);
}
int ans=0;
for(int i=0;i<D;i++) {
    ans=max(ans,dfs(0,i));
}
cout<<ans<<endl;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3740kb

input:

10 2
0
0
2
2
0
3
4
7
2

output:

4

result:

wrong answer 1st lines differ - expected: '6', found: '4'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%