#include <vector>
#include <iostream>
using namespace std;
template <typename T> void print(T elem) {cout << elem << " ";}
template <typename T> void print(vector<T> &v) {for(auto elem: v) print(elem); cout << endl;}
template <typename T> void print(vector<vector<T>> &v) {for(auto elem: v) print(elem); cout << endl;}
void makeG(vector<vector<int>> &g, vector<int> &u, vector<int> &v) {
for(int i=0; i<u.size(); i++) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
}
int decideSubtaskLabel(int n, int k, vector<vector<int>> &g, vector<int> &u, vector<int> &v) {
int subtask = 0, cnt = 0;
bool subtask2 = true;
for(int i=0; i<n; i++) {
if (g[i].size()>2) cnt++;
if (!(u[i]==i+1 && v[i]==i/2 || u[i]==i/2 && v[i]==i+1)) subtask2= false;
}
if (cnt==0) return 1;
if (subtask2) return 2;
if (cnt==1) return 3;
}
void subtask1Label(int n, vector<vector<int>> &g, vector<int> &labels) {
int node = 0;
for(int i=0; i<n; i++)
if(g[i].size()==1) node=i;
int cnt = 0;
while(labels[node]==-1) {
labels[node] = cnt++;
for(int elem: g[node])
if(labels[elem]==-1) node = elem;
}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
vector<vector<int>> g(n);
makeG(g,u,v);
// print(g);
int subtask = decideSubtaskLabel(n,k,g,u,v);
vector<int> labels(n,-1);
switch(subtask) {
case 1: subtask1Label(n,g,labels); return labels;
// case 2:
// case 3:
}
}
int decideSubtaskFind(int s, int t, vector<int> &c) {
return 1;
}
int subtask1Find(int s, int t, vector<int> &c) {
if (c.size()==1) return c[0];
else return t<s? c[0]:c[1];
}
int find_next_station(int s, int t, std::vector<int> c) {
int subtask = decideSubtaskFind(s,t,c);
switch(subtask) {
case 1: return subtask1Find(s,t,c);
}
return c[0];
}
Compilation message
stations.cpp: In function 'void makeG(std::vector<std::vector<int> >&, std::vector<int>&, std::vector<int>&)':
stations.cpp:10:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for(int i=0; i<u.size(); i++) {
| ~^~~~~~~~~
stations.cpp: In function 'int decideSubtaskLabel(int, int, std::vector<std::vector<int> >&, std::vector<int>&, std::vector<int>&)':
stations.cpp:20:19: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
20 | if (!(u[i]==i+1 && v[i]==i/2 || u[i]==i/2 && v[i]==i+1)) subtask2= false;
stations.cpp:16:6: warning: unused variable 'subtask' [-Wunused-variable]
16 | int subtask = 0, cnt = 0;
| ^~~~~~~
stations.cpp:25:1: warning: control reaches end of non-void function [-Wreturn-type]
25 | }
| ^
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:39:25: warning: control reaches end of non-void function [-Wreturn-type]
39 | vector<vector<int>> g(n);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
350 ms |
684 KB |
Output is correct |
2 |
Correct |
283 ms |
684 KB |
Output is correct |
3 |
Correct |
588 ms |
684 KB |
Output is correct |
4 |
Correct |
444 ms |
684 KB |
Output is correct |
5 |
Correct |
449 ms |
684 KB |
Output is correct |
6 |
Correct |
305 ms |
684 KB |
Output is correct |
7 |
Correct |
316 ms |
688 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
2 ms |
776 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
856 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
374 ms |
688 KB |
Output is correct |
2 |
Correct |
309 ms |
684 KB |
Output is correct |
3 |
Correct |
609 ms |
684 KB |
Output is correct |
4 |
Correct |
442 ms |
684 KB |
Output is correct |
5 |
Correct |
412 ms |
684 KB |
Output is correct |
6 |
Correct |
299 ms |
684 KB |
Output is correct |
7 |
Correct |
293 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
776 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
11 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
650 ms |
944 KB |
Output is correct |
2 |
Correct |
451 ms |
684 KB |
Output is correct |
3 |
Correct |
383 ms |
684 KB |
Output is correct |
4 |
Correct |
2 ms |
768 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
0 ms |
768 KB |
Output is correct |
7 |
Runtime error |
2 ms |
600 KB |
Execution killed with signal 6 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
355 ms |
684 KB |
Output is correct |
2 |
Correct |
305 ms |
684 KB |
Output is correct |
3 |
Correct |
589 ms |
684 KB |
Output is correct |
4 |
Correct |
451 ms |
684 KB |
Output is correct |
5 |
Correct |
405 ms |
684 KB |
Output is correct |
6 |
Correct |
314 ms |
684 KB |
Output is correct |
7 |
Correct |
302 ms |
688 KB |
Output is correct |
8 |
Correct |
2 ms |
764 KB |
Output is correct |
9 |
Correct |
1 ms |
776 KB |
Output is correct |
10 |
Correct |
0 ms |
776 KB |
Output is correct |
11 |
Runtime error |
2 ms |
856 KB |
Execution killed with signal 6 |
12 |
Halted |
0 ms |
0 KB |
- |