이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long long
struct DSU{
vector<int> p;
DSU(int n){
p.assign(n + 1, -1);
}
int find(int x){
if (p[x] < 0) return x;
return p[x] = find(p[x]);
}
void merge(int u, int v){
u = find(u);
v = find(v);
if (u == v) return;
if (p[u] > p[v]) swap(u, v);
p[u] += p[v];
p[v] = u;
}
};
vector<vector<int>> v, vr;
vector<int> ord, vis, lb, rb;
void dfs(int x){
vis[x] = 1;
for (auto el : v[x]){
if (vis[el] == 0){
dfs(el);
}
}
ord.push_back(x);
}
int main(){
string inp;
int n, m, c, a, b;
cin>>n>>m>>c;
v.assign(m + 1, vector<int>()), vr.assign(m + 1, vector<int>()), vis.assign(m + 1, 0), lb.assign(m + 1, 1), rb.assign(m + 1, n);
vector<vector<int>> edg;
DSU ds(m + 1);
for (int i = 0; i < c; i++){
string s1 = "", s2 = "";
cin>>inp;
int f = 0;
for (int i = 0; i < inp.size(); i++){
if (inp[i] == '='){
f = 2;
}
else if (inp[i] == '<'){
f = 1;
}
else if (inp[i] == '>'){
f = 3;
}
else{
if (f == 0){
s1 += inp[i];
}
else{
s2 += inp[i];
}
}
}
a = stoi(s1), b = stoi(s2);
if (f == 1){
edg.push_back({a, b});
}
else if (f == 2){
ds.merge(a, b);
}
else{
edg.push_back({b, a});
}
}
for (int i = 0; i < edg.size(); i++){
a = ds.find(edg[i][0]), b = ds.find(edg[i][1]);
v[a].push_back(b);
vr[b].push_back(a);
}
for (int i = 1; i <= m; i++){
if (vis[i] == 0){
dfs(i);
}
}
reverse(ord.begin(), ord.end());
for (auto i : ord){
for (auto el : vr[i]){
lb[i] = max(lb[i], lb[el] + 1);
}
}
reverse(ord.begin(), ord.end());
for (auto i : ord){
for (auto el : v[i]){
rb[i] = min(rb[i], rb[el] - 1);
}
}
for (int i = 1; i <= m; i++){
int a = ds.find(i);
if (lb[a] == rb[a]){
cout<<"K"<<lb[a]<<"\n";
}
else{
cout<<"?\n";
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
kovanice.cpp: In function 'int main()':
kovanice.cpp:45:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for (int i = 0; i < inp.size(); i++){
| ~~^~~~~~~~~~~~
kovanice.cpp:75:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (int i = 0; i < edg.size(); i++){
| ~~^~~~~~~~~~~~
# | 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... |