이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include "stations.h"
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long inf = 2e9;
using namespace std;
vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
ll counter = 0;
vector<vector<ll>> g(n);
rep(i, 0, n - 1) {
g[u[i]].push_back(v[i]);
g[v[i]].push_back(u[i]);
}
ll cur = 0;
queue<ll> q;
rep(i, 0, g.size()) {
if (g[i].size() == 1)q.push(i);
}
vector<int> ans(n);
vector<bool> visited(n);
ll counter2 = 0;
while (!q.empty()) {
cur = q.front();
q.pop();
while (counter < n) {
visited[cur] = 1;
ans[cur] = counter2++;
counter++;
trav(a, g[cur])if (!visited[a])cur = a;
if (g[cur].size() > 2) {
counter2 = ((counter2 / 3000) + 1) * 3000;
ans[cur] = 1e5;
break;
}
}
}
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
int ans;
if (s == 1e5) {
trav(a, c) {
if (abs(a - t) < 1000)ans = a;
}
}
else if (abs(s - t) > 1000) {
ans = -1;
trav(a, c)ans = max(a, ans);
}
else if (s < t) {
ans = -1;
trav(a, c)ans = max(a, ans);
}
else {
ans = 1e7;
trav(a, c)ans = min(a, ans);
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:73:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
73 | return ans;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |