Submission #308688

# Submission time Handle Problem Language Result Execution time Memory
308688 2020-10-01T17:08:48 Z nadorb Stations (IOI20_stations) C++14
0 / 100
885 ms 1036 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];
    if(s<c[0]){
        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){
            c[0]=0;
        }
        else{
            for(unsigned long long i=1;i<c.size();i++){
                if(t<=c[i]){
                    ki=c[i];
                    break;
                }
            }
        }
    }

	return ki;
}
# Verdict Execution time Memory Grader output
1 Incorrect 550 ms 1008 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 554 ms 1024 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 698 ms 1008 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 885 ms 648 KB Output is correct
2 Incorrect 714 ms 640 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 602 ms 1036 KB Wrong query response.
2 Halted 0 ms 0 KB -