Submission #1071422

#TimeUsernameProblemLanguageResultExecution timeMemory
1071422KaleemRazaSyedBeech Tree (IOI23_beechtree)C++17
0 / 100
1625 ms2097152 KiB
#include<bits/stdc++.h> #include "beechtree.h" using namespace std; const int N = 200'000 + 10; vector<int> child[N], subtree[N]; int n, h[N]; bool compare(int x, int y) { if(child[x].size() == child[y].size()) return h[x] < h[y]; return child[x].size() > child[y].size(); } bool check(int a, int b, vector<int> &C) { set<int> st; for(int c : child[a]) st.insert(C[c]); for(int c : child[b]) if(st.find(C[c]) == st.end()) return false; return true; } void dfs(int v, vector<int> &ans, vector<int> &C, vector<int> &P) { subtree[v].push_back(v); if(child[v].empty()) { ans[v] = 1; return; } for(int c : child[v]) { h[c] = h[v] + 1; dfs(c, ans, C, P); for(int i : subtree[c]) subtree[v].push_back(i); subtree[c].clear(); } int cnt = 0; set<int> st; for(int c : child[v]) { st.insert(C[c]); if(!child[c].empty()) cnt++; if(ans[c] == 0) { ans[v] = 0; return; } } if(st.size() != child[v].size()) { ans[v] = 0; return; } sort(subtree[v].begin(), subtree[v].end(), compare); bool ok = (subtree[v][0] == v); map<int,int> mp; for(int i = 1; i < subtree[v].size() && ok; i++) { int u = subtree[v][i]; ok &= (subtree[v][mp[C[u]]] == P[u]); mp[C[u]]++; } ans[v] = ok; } vector<int> beechtree(int N, int M, vector<int> P, vector<int> C) { for(int i = 1; i < N; i ++) child[P[i]].push_back(i); vector<int> ans(N); dfs(0, ans, C, P); return ans; }

Compilation message (stderr)

beechtree.cpp: In function 'void dfs(int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
beechtree.cpp:69:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |   for(int i = 1; i < subtree[v].size() && ok; i++)
      |                  ~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...