#include<bits/stdc++.h>
#include "stations.h"
using namespace std ;
#define maxn 200009
#define ll long long
#define pb push_back
#define fi first
#define se second
#define left id<<1
#define right id<<1|1
#define re exit(0);
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1
const int mod = 1e9+7 ;
const int INF = 1e9 ;
typedef vector<int> vi ;
typedef pair<int,int> pii ;
typedef vector<pii> vii ;
template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; }
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; }
void add ( int &a , int b )
{
a += b ;
if ( a >= mod ) a -= mod ;
if ( a < 0 ) a += mod ;
}
void rf ()
{
freopen ("bai1.inp","r",stdin) ;
}
int _pow ( int a , int n )
{
if ( n == 0 ) return 1 ;
int res = _pow (a,n/2) ;
if ( n % 2 ) return 1ll*res*res%mod*a%mod ;
else return 1ll*res*res%mod ;
}
//vi label ( int N , int K , vi U , vi V ) ;
//int find_next_station ( int s , int t , int c ) ;
//
//int main ()
//{
// ios_base::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// rf () ;
// int n , k ;
// vi u , v ;
// cin >> n >> k ;
// for ( int i = 0 ; i < n-1 ; i ++ )
// {
// int _u , _v ; cin >> _u >> _v ;
// u . pb (_u) , v . pb (_v) ;
// }
// vi res = label (n,k,u,v) ;
//}
vi adjList [maxn] ;
int n , k ;
vi label ( int N , int K , vi U , vi V )
{
for ( int i = 0 ; i < n ; i ++ ) adjList [i] . clear () ;
n = N , k = K ;
for ( int i = 0 ; i < n-1 ; i ++ )
{
adjList [U[i]] . pb (V[i]) ;
adjList [V[i]] . pb (U[i]) ;
}
int root = -1 ;
for ( int i = 0 ; i < n ; i ++ ) if ( adjList [i].size () == 1 ) root = i ;
vi res(n,-1) ;
int num = 0 ;
stack <int> q ;
q . push (root) ;
while ( q.size () )
{
int u = q.top() ; q.pop() ; res [u] = num ++ ;
for ( auto v : adjList [u] ) if ( res [v] == -1 ) q . push (v) ;
}
return res ;
}
int find_next_station ( int s , int t , vi c )
{
for ( auto x : c )
{
if ( s <= x && x <= t ) return x ;
if ( s >= x && x >= t ) return x ;
}
}
Compilation message
stations.cpp: In function 'void rf()':
stations.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen ("bai1.inp","r",stdin) ;
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, vi)':
stations.cpp:95:1: warning: control reaches end of non-void function [-Wreturn-type]
95 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
346 ms |
10140 KB |
Output is correct |
2 |
Correct |
289 ms |
10168 KB |
Output is correct |
3 |
Correct |
593 ms |
9900 KB |
Output is correct |
4 |
Correct |
501 ms |
10096 KB |
Output is correct |
5 |
Correct |
338 ms |
9900 KB |
Output is correct |
6 |
Correct |
249 ms |
10132 KB |
Output is correct |
7 |
Correct |
274 ms |
9900 KB |
Output is correct |
8 |
Correct |
3 ms |
9988 KB |
Output is correct |
9 |
Correct |
4 ms |
9988 KB |
Output is correct |
10 |
Correct |
2 ms |
9984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
15264 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
328 ms |
10140 KB |
Output is correct |
2 |
Correct |
290 ms |
10144 KB |
Output is correct |
3 |
Correct |
586 ms |
9900 KB |
Output is correct |
4 |
Correct |
434 ms |
10108 KB |
Output is correct |
5 |
Correct |
368 ms |
9900 KB |
Output is correct |
6 |
Correct |
270 ms |
10136 KB |
Output is correct |
7 |
Correct |
296 ms |
9900 KB |
Output is correct |
8 |
Correct |
3 ms |
9980 KB |
Output is correct |
9 |
Correct |
5 ms |
9988 KB |
Output is correct |
10 |
Correct |
2 ms |
9980 KB |
Output is correct |
11 |
Runtime error |
6 ms |
15020 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
556 ms |
9900 KB |
Output is correct |
2 |
Correct |
453 ms |
9900 KB |
Output is correct |
3 |
Correct |
370 ms |
9900 KB |
Output is correct |
4 |
Correct |
3 ms |
9984 KB |
Output is correct |
5 |
Correct |
4 ms |
9984 KB |
Output is correct |
6 |
Correct |
4 ms |
9984 KB |
Output is correct |
7 |
Runtime error |
6 ms |
15020 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
372 ms |
10140 KB |
Output is correct |
2 |
Correct |
301 ms |
10144 KB |
Output is correct |
3 |
Correct |
580 ms |
9900 KB |
Output is correct |
4 |
Correct |
461 ms |
9900 KB |
Output is correct |
5 |
Correct |
372 ms |
9900 KB |
Output is correct |
6 |
Correct |
318 ms |
10132 KB |
Output is correct |
7 |
Correct |
323 ms |
9900 KB |
Output is correct |
8 |
Correct |
3 ms |
9988 KB |
Output is correct |
9 |
Correct |
4 ms |
10236 KB |
Output is correct |
10 |
Correct |
3 ms |
9988 KB |
Output is correct |
11 |
Runtime error |
8 ms |
15268 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |