이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "simurgh.h"
#include <bits/stdc++.h>
typedef long long ll;
#define pii pair<int, int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define FOR(i, n) for (int i = 0; i < n; i++)
using namespace std;
set<pii> cur;
map<pii, int> fin;
map<pii, int> label;
vector<vector<int>> adj;
vector<int> vis;
vector<int> tovec(set<pii> a){
vector<int> res;
for (auto &i : a) {
res.push_back(label[i]);
}
return res;
}
pii sdfs(int a, int p){
vis[a] = 2;
pii res = {1, 0};
for (auto &b : adj[a]) {
if(vis[b] != 2) {
pii ret = sdfs(b, a);
res.fi += ret.fi;
res.se += ret.se;
}
}
if(a == 0) return res;
int base = count_common_roads(tovec(cur));
cur.erase({p, a});
set<int> samepar;
bool parroyal = (res.se < res.fi);
for (auto &b : adj[a]) {
if(cur.find({a, b}) == cur.end() && cur.find({b, a}) == cur.end()){
cur.insert({a, b});
int cnt = count_common_roads(tovec(cur));
cur.erase({a, b});
if(cnt == base) samepar.insert(b);
if(cnt < base) parroyal = 1;
if(cnt > base) parroyal = 0;
}
}
for (auto &b : adj[a]) {
if(cur.find({a, b}) == cur.end() && cur.find({b, a}) == cur.end()){
if(samepar.find(b) != samepar.end()){
if(parroyal) {
fin[{a, b}] = 1;
res.se++;
}
}
else {
if(!parroyal) {
fin[{a, b}] = 1;
res.se++;
}
}
}
}
cur.insert({p, a});
return res;
}
void dfs(int a){
vis[a] = 1;
for (auto &b : adj[a]) {
if(!vis[b]) {
cur.insert({a, b});
dfs(b);
}
}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
adj.resize(n);
vis.resize(n);
FOR(i, u.size()){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
label[{u[i], v[i]}] = i;
label[{v[i], u[i]}] = i;
}
dfs(0);
sdfs(0, 0);
vector<int> res;
for (auto &i : fin) {
if(i.se == 1) res.push_back(label[i.fi]);
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:9:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define FOR(i, n) for (int i = 0; i < n; i++)
......
86 | FOR(i, u.size()){
| ~~~~~~~~~~~
simurgh.cpp:86:2: note: in expansion of macro 'FOR'
86 | FOR(i, u.size()){
| ^~~
# | 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... |