Submission #958260

# Submission time Handle Problem Language Result Execution time Memory
958260 2024-04-05T08:48:35 Z 8pete8 Stations (IOI20_stations) C++17
100 / 100
593 ms 1364 KB
#include "stations.h"
#include <vector>
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<numeric> //gcd(a,b)
#include<cmath>
#include<set>
#include<cassert>
#include<algorithm>
#include<bitset> 
#include<stack>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define pppiiii pair<pii,pii>
#define ppii pair<int,pii>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
//#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
const int mxn=1e3;
vector<int>adj[mxn+10];
int tin[mxn+10],tout[mxn+10],t=-1;
vector<int>v,lab;
void dfs(int cur,int p){
	if(!lab[cur])tin[cur]=++t;
	for(auto i:adj[cur])if(i!=p)dfs(i,cur);
	if(lab[cur])tout[cur]=++t;
}
vector<int> label(int n, int k,vector<int> U,vector<int> V) {
	v.assign(n,0),lab.assign(n,0);
	t=-1;
	for(int i=0;i<n-1;i++)adj[U[i]].pb(V[i]),adj[V[i]].pb(U[i]);
	queue<pii>q;
	lab[0]=1;
	q.push({0,0});
	while(!q.empty()){
		int cur=q.front().f,p=q.front().s;
		q.pop();
		lab[cur]=lab[p]^1;
		for(auto i:adj[cur])if(i!=p)q.push({i,cur});
	}
	dfs(0,-1);
	for(int i=0;i<n;i++)v[i]=((lab[i])?tout[i]:tin[i]);
	for(int i=0;i<n;i++)adj[i].clear();
	return v;
}
int find_next_station(int a, int b, vector<int> c){
	if(a<c[0]){
		//a is tin,other is tout
		if(b<a||b>=c.back())return c.back();//outside subtree
		for(int i=1;i<c.size();i++)if(c[i-1]<b&&b<=c[i])return c[i];
		return c[0];
	}
	else{
		//a is tout,other is tin
		if(b>a||b<=c[0])return c[0];
		for(int i=0;i<c.size()-1;i++)if(c[i]<=b&&b<c[i+1])return c[i];
		return c.back();
	}
}/*
int main(){
	int n,k;cin>>n>>k;
	vector<int>a(n-1),b(n-1);
	for(int i=0;i<n-1;i++)cin>>a[i];
	for(int i=0;i<n-1;i++)cin>>b[i];
	vector<int>bruh=label(n,k,a,b);
	for(auto i:bruh)cout<<i<<" ";
	vector<int>g;
	for(auto i:adj[1])g.pb(bruh[i]);
	cout<<find_next_station(9,7,g)<<"B\n";
}*/

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i=1;i<c.size();i++)if(c[i-1]<b&&b<=c[i])return c[i];
      |               ~^~~~~~~~~
stations.cpp:71:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for(int i=0;i<c.size()-1;i++)if(c[i]<=b&&b<c[i+1])return c[i];
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 336 ms 928 KB Output is correct
2 Correct 305 ms 932 KB Output is correct
3 Correct 593 ms 684 KB Output is correct
4 Correct 441 ms 684 KB Output is correct
5 Correct 355 ms 684 KB Output is correct
6 Correct 272 ms 916 KB Output is correct
7 Correct 299 ms 684 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 2 ms 772 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 876 KB Output is correct
2 Correct 345 ms 1080 KB Output is correct
3 Correct 541 ms 684 KB Output is correct
4 Correct 447 ms 684 KB Output is correct
5 Correct 367 ms 684 KB Output is correct
6 Correct 279 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 344 ms 932 KB Output is correct
2 Correct 267 ms 1184 KB Output is correct
3 Correct 541 ms 684 KB Output is correct
4 Correct 447 ms 684 KB Output is correct
5 Correct 372 ms 684 KB Output is correct
6 Correct 286 ms 912 KB Output is correct
7 Correct 285 ms 684 KB Output is correct
8 Correct 2 ms 764 KB Output is correct
9 Correct 3 ms 768 KB Output is correct
10 Correct 0 ms 764 KB Output is correct
11 Correct 390 ms 940 KB Output is correct
12 Correct 286 ms 996 KB Output is correct
13 Correct 293 ms 1292 KB Output is correct
14 Correct 263 ms 684 KB Output is correct
15 Correct 35 ms 768 KB Output is correct
16 Correct 40 ms 856 KB Output is correct
17 Correct 60 ms 880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 559 ms 684 KB Output is correct
2 Correct 472 ms 684 KB Output is correct
3 Correct 363 ms 684 KB Output is correct
4 Correct 2 ms 1016 KB Output is correct
5 Correct 2 ms 768 KB Output is correct
6 Correct 0 ms 768 KB Output is correct
7 Correct 356 ms 684 KB Output is correct
8 Correct 539 ms 684 KB Output is correct
9 Correct 395 ms 684 KB Output is correct
10 Correct 393 ms 684 KB Output is correct
11 Correct 4 ms 764 KB Output is correct
12 Correct 3 ms 764 KB Output is correct
13 Correct 2 ms 768 KB Output is correct
14 Correct 3 ms 772 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
16 Correct 331 ms 684 KB Output is correct
17 Correct 327 ms 684 KB Output is correct
18 Correct 357 ms 684 KB Output is correct
19 Correct 319 ms 684 KB Output is correct
20 Correct 321 ms 684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 359 ms 924 KB Output is correct
2 Correct 305 ms 924 KB Output is correct
3 Correct 578 ms 684 KB Output is correct
4 Correct 434 ms 684 KB Output is correct
5 Correct 366 ms 684 KB Output is correct
6 Correct 288 ms 896 KB Output is correct
7 Correct 274 ms 684 KB Output is correct
8 Correct 2 ms 944 KB Output is correct
9 Correct 2 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 289 ms 876 KB Output is correct
12 Correct 326 ms 848 KB Output is correct
13 Correct 570 ms 684 KB Output is correct
14 Correct 476 ms 688 KB Output is correct
15 Correct 383 ms 684 KB Output is correct
16 Correct 317 ms 684 KB Output is correct
17 Correct 353 ms 684 KB Output is correct
18 Correct 305 ms 1036 KB Output is correct
19 Correct 290 ms 1296 KB Output is correct
20 Correct 291 ms 684 KB Output is correct
21 Correct 38 ms 964 KB Output is correct
22 Correct 44 ms 852 KB Output is correct
23 Correct 56 ms 880 KB Output is correct
24 Correct 2 ms 764 KB Output is correct
25 Correct 2 ms 932 KB Output is correct
26 Correct 2 ms 764 KB Output is correct
27 Correct 3 ms 764 KB Output is correct
28 Correct 1 ms 768 KB Output is correct
29 Correct 346 ms 684 KB Output is correct
30 Correct 332 ms 684 KB Output is correct
31 Correct 359 ms 684 KB Output is correct
32 Correct 344 ms 684 KB Output is correct
33 Correct 304 ms 684 KB Output is correct
34 Correct 180 ms 924 KB Output is correct
35 Correct 259 ms 1260 KB Output is correct
36 Correct 290 ms 1176 KB Output is correct
37 Correct 281 ms 1172 KB Output is correct
38 Correct 328 ms 1044 KB Output is correct
39 Correct 317 ms 1172 KB Output is correct
40 Correct 301 ms 1276 KB Output is correct
41 Correct 285 ms 1164 KB Output is correct
42 Correct 38 ms 896 KB Output is correct
43 Correct 57 ms 912 KB Output is correct
44 Correct 81 ms 896 KB Output is correct
45 Correct 93 ms 908 KB Output is correct
46 Correct 172 ms 868 KB Output is correct
47 Correct 204 ms 904 KB Output is correct
48 Correct 33 ms 1364 KB Output is correct
49 Correct 32 ms 1216 KB Output is correct