Submission #49833

# Submission time Handle Problem Language Result Execution time Memory
49833 2018-06-03T11:46:37 Z A_H_Ghaznavi Birokracija (COCI18_birokracija) C++14
60 / 100
1000 ms 16000 KB
// In the name of god
// A.H.Ghaznavi
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200010;
int n,a[maxn],ansmain[maxn];
vector <int> v[maxn];
queue <int> q;
pair <int ,int> ans[maxn];
bool mark[maxn],rad[maxn];
void bfs(int z)
{
    mark[z]=true;
    for (int i=0;i<v[z].size();i++)
    {
        if (!mark[v[z][i]] || (mark[v[z][i]] && ans[z].first+1<ans[v[z][i]].first))
        {
            ans[v[z][i]].first=ans[z].first+1;
            q.push(v[z][i]);
            mark[v[z][i]]=true;
        }
    }
    q.pop();
    if (q.empty())
        return;
    bfs(q.front());
}
int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        ans[i].second=i;
    for (int i=2;i<=n;i++)
    {
        cin>>a[i];
        v[a[i]].push_back(i);
    }
    q.push(1);
    bfs(1);
    sort (ans, ans+n+1);
    for (int i=1;i<=n;i++)
    {
        for (int i2=1;i2<=n;i2++)
            rad[i2]=false;
        rad[ans[i].second]=true;
        for (int i2=i;i2<=n;i2++)
        {
            if (ans[i2].first<=ans[i].first)
                continue;
            if (rad[a[ans[i2].second]])
            {
                ansmain[ans[i].second]+=(ans[i2].first-ans[i].first+1);
                rad[ans[i2].second]=true;
            }
        }
        ansmain[ans[i].second]++;
    }
    for (int i=1;i<=n;i++)
        cout<<ansmain[i]<<" ";
    return 0;
}

Compilation message

birokracija.cpp: In function 'void bfs(int)':
birokracija.cpp:15:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0;i<v[z].size();i++)
                  ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5236 KB Output is correct
2 Correct 6 ms 5256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5400 KB Output is correct
2 Correct 7 ms 5400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5400 KB Output is correct
2 Correct 7 ms 5400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 554 ms 6208 KB Output is correct
2 Correct 729 ms 6720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 8644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 14084 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1090 ms 14976 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1073 ms 16000 KB Time limit exceeded
2 Halted 0 ms 0 KB -