Submission #308721

# Submission time Handle Problem Language Result Execution time Memory
308721 2020-10-01T18:11:29 Z nadorb Stations (IOI20_stations) C++14
0 / 100
860 ms 1024 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>>graf;
vector<int>visit;
vector<pair<int,int>>beki;

void dfs(int v,int &ido){
    visit[v]=1;
    beki[v].first=ido;
    ido++;
    for(int i:graf[v]){
        if(!visit[i]){
            dfs(i,ido);
        }
    }
    beki[v].second=ido;
    ido++;
}


vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> labels(n),tav(n,-1);
	graf.assign(n,{});   //clear+resize=assign
	visit.assign(n,0);
	beki.assign(n,{});
	int ido=0;
	for (int i = 0; i<n-1; i++) {
		graf[u[i]].push_back(v[i]);
		graf[v[i]].push_back(u[i]);
	}
	dfs(0,ido);
	//bfs
    queue<int>q;
    q.push(0);
    tav[0]=0;
    while(!q.empty()){
        int d=q.front();
        q.pop();
        for(int i:graf[d]){
            if(tav[i]==-1){
                tav[i]=(tav[d]+1)%2;
        q.push(i);
            }
        }
    }
    //bfs end
	for(int i=0;i<n;i++){
        if(tav[i]==0){
            labels[i]=(beki[i].first)/2;
        }
        else{
            labels[i]=(beki[i].second)/2;
        }
	}
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
    int ki=c[0];
    bool b=0;
    if(s<c[0]){
        b=1;
        s=1000-s;
        t=1000-t;
        for(int i:c){
            i=1000-i;
        }
    }
    sort(c.begin(),c.end());
    if(c.size()!=1){
        if(t<c[1] || t>s){
            ki=c[0]; //semmi
        }
        else{
            for(unsigned long long i=1;i<c.size();i++){
                if(t>=c[i]){
                    ki=c[i];
                    if(b){
                        ki=1000-ki;
                    }
                }
            }
        }
    }
	return ki;
}
# Verdict Execution time Memory Grader output
1 Incorrect 540 ms 1008 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 447 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 533 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 860 ms 644 KB Output is correct
2 Incorrect 649 ms 644 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 508 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -