답안 #388197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
388197 2021-04-10T13:26:12 Z Supersonic 기지국 (IOI20_stations) C++14
0 / 100
819 ms 1012 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
int c[1001];set<int> a[1001];int l[1001];
int ch(int k,int p){
	int t=a[k].size()-1;for(auto i:a[k])if(i!=p)t+=ch(i,k);
	//if(k==0)for(auto i:a[k])cerr<<i<<'=';cout<<endl;
	if(k==0)t++;c[k]=t;return t;
}
void as(int k,int p,int v,int g){
	//cerr<<k<<' '<<p<<' '<<v<<' '<<g<<endl;
	int j=v;l[k]=v;
	for(auto i:a[k])if(i!=p){j+=(c[i]+1)*g;as(i,k,j,g*(-1));}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	for(int i=0;i<n-1;i++){
		a[u[i]].insert(v[i]);
		a[v[i]].insert(u[i]);
	}
	int r=ch(0,-1);as(0,-1,0,1);
	//for(int i=0;i<n;i++){cerr<<i<<'-'<<c[i]<<endl;}
	vector<int> f;for(int i=0;i<n;i++){f.push_back(l[i]);//cerr<<i<<':'<<l[i]<<endl;
	}
	memset(c,0,sizeof(c));memset(l,0,sizeof(l));for(int i=0;i<1001;i++)a[i].clear();
	return f;
}

int find_next_station(int s, int t, std::vector<int> c) {
	int n=c.size();
	//cerr<<s<<' '<<t<<endl;for(auto i:c)cerr<<i<<'-';cerr<<endl;
	if(s==0){
		for(int i=0;i<n;i++){if(t==c[i])return t;if(c[i]>t)return c[i];}
	}
	else if(s<c[0]){
		for(int i=0;i<n-1;i++){if(t==c[i])return t;if(c[i]>t)return c[i];}
		return c[n-1];
	}
	else{
		for(int i=n-1;i>=1;i--){if(t==c[i])return t;if(t>c[i])return c[i];}
		return c[0];
	}
	exit(1);
	return c[0];
}

Compilation message

stations.cpp: In function 'int ch(int, int)':
stations.cpp:8:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    8 |  if(k==0)t++;c[k]=t;return t;
      |  ^~
stations.cpp:8:14: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    8 |  if(k==0)t++;c[k]=t;return t;
      |              ^
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:20:6: warning: unused variable 'r' [-Wunused-variable]
   20 |  int r=ch(0,-1);as(0,-1,0,1);
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 527 ms 784 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 407 ms 840 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 498 ms 1012 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 819 ms 656 KB Output is correct
2 Correct 614 ms 664 KB Output is correct
3 Incorrect 534 ms 784 KB Wrong query response.
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 534 ms 776 KB Wrong query response.
2 Halted 0 ms 0 KB -