#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
#define what_is(a) cout << #a << " is " << a << "\n"
#define checker(a) cout <"checker reached " << a << "\n"
#define ll long long
vector<vector<int>> adj(1000,vector<int>());
vector<int> lbl;
void dfs(int u,int p,int d){
lbl[u]=d++;
for(int v:adj[u])
if(v!=p)
dfs(v,u,d);
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
lbl = vector<int>(n);
for(int i=0;i<n;i++)
adj[i] = vector<int>();
for(int i=0;i<n-1;i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
int src = -1;
for(int i=0;i<n;i++)
if(adj[i].size()>2)src = i;
if(src==-1)
for(int i=0;i<n;i++)
if(adj[i].size()==1)src = i;
lbl[src]=0;
int d = 1;
for(int a:adj[src]){
dfs(a,src,d);
d+=1000;
}
return lbl;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(t==0)return s-1;
if(s==0)return ((ll)t/1000LL)*1000LL + 1LL;
if(s/1000==t/1000){
if(s<t)return s+1;
else return s-1;
}else{
if((s-1)%1000==0)return 0/0;
return s-1;
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:52:28: warning: division by zero [-Wdiv-by-zero]
52 | if((s-1)%1000==0)return 0/0;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
606 ms |
608 KB |
Output is correct |
2 |
Correct |
497 ms |
520 KB |
Output is correct |
3 |
Correct |
1160 ms |
400 KB |
Output is correct |
4 |
Correct |
823 ms |
516 KB |
Output is correct |
5 |
Correct |
728 ms |
400 KB |
Output is correct |
6 |
Correct |
554 ms |
636 KB |
Output is correct |
7 |
Correct |
509 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
312 KB |
Invalid labels (duplicates values). scenario=0, label=10 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
670 ms |
528 KB |
Output is correct |
2 |
Correct |
517 ms |
528 KB |
Output is correct |
3 |
Correct |
950 ms |
540 KB |
Output is correct |
4 |
Correct |
782 ms |
528 KB |
Output is correct |
5 |
Correct |
736 ms |
528 KB |
Output is correct |
6 |
Correct |
527 ms |
512 KB |
Output is correct |
7 |
Correct |
511 ms |
656 KB |
Output is correct |
8 |
Correct |
3 ms |
484 KB |
Output is correct |
9 |
Correct |
6 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Runtime error |
2 ms |
760 KB |
Execution killed with signal 4 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1093 ms |
400 KB |
Output is correct |
2 |
Correct |
817 ms |
400 KB |
Output is correct |
3 |
Correct |
675 ms |
516 KB |
Output is correct |
4 |
Correct |
3 ms |
468 KB |
Output is correct |
5 |
Correct |
6 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Runtime error |
2 ms |
784 KB |
Execution killed with signal 4 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
619 ms |
528 KB |
Output is correct |
2 |
Correct |
515 ms |
528 KB |
Output is correct |
3 |
Correct |
1073 ms |
528 KB |
Output is correct |
4 |
Correct |
812 ms |
512 KB |
Output is correct |
5 |
Correct |
709 ms |
508 KB |
Output is correct |
6 |
Correct |
547 ms |
504 KB |
Output is correct |
7 |
Correct |
556 ms |
528 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Incorrect |
5 ms |
316 KB |
Invalid labels (duplicates values). scenario=0, label=10 |
12 |
Halted |
0 ms |
0 KB |
- |