# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1064788 |
2024-08-18T17:45:08 Z |
XJP12 |
Stations (IOI20_stations) |
C++14 |
|
647 ms |
1020 KB |
#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
vvi g;
vi vis;
vi l;
vi indeg;
int y=-1;
int cont=0;
void dfs1(int u, int p){
// cout<<u<< " ";
vis[u]=true;
if(u==y){
l[u]=1000+l[p];
}else{
l[u]=cont;
cont++;
}
for(auto v: g[u]){
if(!vis[v]){
dfs1(v,u);
}
}
}
void dfs(int u){
vis[u]=true;
l[u]=cont;
cont++;
for(auto v: g[u]){
if(!vis[v]){
dfs(v);
}
}
}
vi label(int n, int k, vi u, vi v) {
l.assign(n,0);
vis.assign(n,0);
indeg.assign(n,0);
g.assign(n, vi());
y=-1;
cont=0;
for(int i=0; i<n-1; i++){
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
indeg[u[i]]++;
indeg[v[i]]++;
}
vi x;
for(int i=n-1; i>=0; i--){
if(indeg[i]==1) x.push_back(i);
if(indeg[i]==3) y=i;
// cout<<x<<y<<endl;
}
if(k>1000 && y!=-1){
int a=g[y][0], b = g[y][1], c=g[y][2];
int x1=-1;
for(int i=0; i<(int)x.size(); i++){
if(x[i]!=a && x[i]!=b && x[i]!=c){
x1=x[i];
}else{
if(x[i]==a) y=a;
if(x[i]==b) y=b;
if(x[i]==c) y=c;
}
}
// cout<<y<<endl;
if(x1==-1){
if(y!=a){
x1=a;
}else{
x1=b;
}
}
dfs1(x1,x1);
}else{
dfs(x[0]);
}
return l;
}
int find_next_station(int s, int t, vi c) {
// return 0;
int size = (int)c.size();
if(size==1)return c[0];
for(int i=0; i<size; i++){
if(c[i]==t) return c[i];
}
if(s<=1000 && t<=1000){
if(t>s){
return c[1];
}else{
return c[0];
}
}else{
if(t-1000>s){
return c[1];
}else{
return c[0];
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
367 ms |
684 KB |
Output is correct |
2 |
Correct |
332 ms |
684 KB |
Output is correct |
3 |
Correct |
581 ms |
684 KB |
Output is correct |
4 |
Correct |
474 ms |
684 KB |
Output is correct |
5 |
Correct |
405 ms |
684 KB |
Output is correct |
6 |
Correct |
287 ms |
684 KB |
Output is correct |
7 |
Correct |
285 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
764 KB |
Output is correct |
9 |
Correct |
1 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
324 ms |
684 KB |
Wrong query response. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
374 ms |
684 KB |
Output is correct |
2 |
Correct |
316 ms |
684 KB |
Output is correct |
3 |
Correct |
647 ms |
684 KB |
Output is correct |
4 |
Correct |
461 ms |
684 KB |
Output is correct |
5 |
Correct |
383 ms |
684 KB |
Output is correct |
6 |
Correct |
313 ms |
684 KB |
Output is correct |
7 |
Correct |
299 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
780 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
768 KB |
Output is correct |
11 |
Correct |
373 ms |
684 KB |
Output is correct |
12 |
Incorrect |
326 ms |
1020 KB |
Wrong query response. |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
580 ms |
684 KB |
Output is correct |
2 |
Correct |
442 ms |
684 KB |
Output is correct |
3 |
Correct |
345 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
2 ms |
768 KB |
Output is correct |
6 |
Correct |
0 ms |
768 KB |
Output is correct |
7 |
Correct |
399 ms |
684 KB |
Output is correct |
8 |
Correct |
636 ms |
684 KB |
Output is correct |
9 |
Correct |
471 ms |
684 KB |
Output is correct |
10 |
Correct |
410 ms |
684 KB |
Output is correct |
11 |
Incorrect |
3 ms |
764 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
354 ms |
892 KB |
Output is correct |
2 |
Correct |
324 ms |
684 KB |
Output is correct |
3 |
Correct |
596 ms |
684 KB |
Output is correct |
4 |
Correct |
420 ms |
684 KB |
Output is correct |
5 |
Correct |
467 ms |
684 KB |
Output is correct |
6 |
Correct |
317 ms |
684 KB |
Output is correct |
7 |
Correct |
298 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
764 KB |
Output is correct |
10 |
Correct |
0 ms |
764 KB |
Output is correct |
11 |
Incorrect |
333 ms |
964 KB |
Wrong query response. |
12 |
Halted |
0 ms |
0 KB |
- |