Submission #313454

# Submission time Handle Problem Language Result Execution time Memory
313454 2020-10-16T03:29:48 Z qiangbao Stations (IOI20_stations) C++14
0 / 100
1 ms 384 KB
#include <iostream>
#include <algorithm>
#include <vector>

#define pb push_back

using namespace std;

typedef pair<int, int> pii;

vector<int> con[1001];
vector<int> son[1001];
bool used[1001];

vector<int> ans;

void rt(int x)
{
    int i;
    
    used[x]=true;
    for(i=0;i<con[x].size();i++){
        int f=con[x][i];
        if(!used[f])
            son[x].pb(f), used[f]=true, rt(f);
    }
}

pii wk(int x, int lev, int label)
{
    pii ret={label, 1};
    int i;
    
    if(lev%2==0){
        ans[x]=label;
        for(i=0;i<son[x].size();i++){
            pii f=wk(son[x][i], lev+1, label+1);
            label+=f.second;
            ret.first=max(ret.first, f.first);
            ret.second+=f.second;
        }
    }
    if(lev%2==1){
        for(i=0;i<son[x].size();i++){
            pii f=wk(son[x][i], lev+1, label);
            label+=f.second;
            ret.first=max(ret.first, f.first);
            ret.second+=f.second;
        }
        ans[x]=label;
    }
    
    return ret;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
    int i;
    for(i=0;i<=1000;i++){
        con[i].clear();
        son[i].clear();
        used[i]=false;
    }
    ans.clear();
    
    for(i=0;i<n-1;i++){
        con[u[i]].pb(v[i]);
        con[v[i]].pb(u[i]);
        ans.pb(0);
    }
    rt(0);
    wk(0, 1, 1);
    
    return ans;
}

int find_next_station(int s, int t, vector<int> nei)
{
    int lev=1;
    int i;
    
    for(i=0;i<nei.size();i++)
        if(nei[i]>s)
            lev=0;
    
    if(lev==1){
        sort(nei.begin(), nei.end());
        bool maxi=false;
        if(t<=nei[0] || t>s)
            maxi=true;
        if(maxi)
            return nei[0];
        for(i=int(nei.size())-1;i>=0;i--)
            if(t>=nei[i])
                return nei[i];
    }
    else{
        sort(nei.begin(), nei.end());
        bool mini=false;
        if(t>=nei[nei.size()-1] || t<s)
            mini=true;
        if(mini)
            return nei[nei.size()-1];
        for(i=0;i<nei.size();i++)
            if(t<=nei[i])
                return nei[i];
    }
    
    return -1;
}

//int main()
//{
//    int i;
//
//    label(6, 5, {0, 1, 2, 3, 4}, {1, 2, 3, 4, 5});
//    for(i=0;i<6;i++)
//        cout << ans[i] << " ";
//    cout << endl;
//
//    cout << find_next_station(3, 1, {1, 2}) << endl;
//}

Compilation message

stations.cpp: In function 'void rt(int)':
stations.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(i=0;i<con[x].size();i++){
      |             ~^~~~~~~~~~~~~~
stations.cpp: In function 'pii wk(int, int, int)':
stations.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(i=0;i<son[x].size();i++){
      |                 ~^~~~~~~~~~~~~~
stations.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for(i=0;i<son[x].size();i++){
      |                 ~^~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:82:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(i=0;i<nei.size();i++)
      |             ~^~~~~~~~~~~
stations.cpp:104:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |         for(i=0;i<nei.size();i++)
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Invalid length of array as the response of 'label'. scenario=0, n=10, len=9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Invalid length of array as the response of 'label'. scenario=0, n=996, len=995
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Invalid length of array as the response of 'label'. scenario=0, n=2, len=1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Invalid length of array as the response of 'label'. scenario=0, n=2, len=1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Invalid length of array as the response of 'label'. scenario=0, n=3, len=2
2 Halted 0 ms 0 KB -