이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define N 100005
int n, w, k, id[N], beg;
pair <int, int> wall[N][4], pos[N];
pair <pair <int, int>, int > p[N];
bool vis[2 * N], brok[2 * N], stacked[N];
int dfs(int dir, int u){
// cout << u << endl;
stacked[u] = 1;
int t = dir + 3;
t %= 4;
// cout << u<< endl;s
while (t != (dir + 2) % 4){
if (!vis[wall[u][t].S]) {
vis[wall[u][t].S] = 1;
// cout << wall[u][t].S<< endl;
if (stacked[wall[u][t].F]) {
stacked[u] = 0;
brok[wall[u][t].S] = 1;
return wall[u][t].F;
}
int cyc = dfs(t, wall[u][t].F);
if (cyc != -1){
brok[wall[u][t].S] = 1;
if (cyc != u){
stacked[u] = 0;
return cyc;
}
}
}
t++;
t %= 4;
}
stacked[u] = 0;
return -1;
}
int main (){
vis[0] = 1;
cin >> n;
for (int i = 1;i <= n;i++) {
p[i].S = i;
cin >> p[i].F.F >> p[i].F.S;
pos[i] = p[i].F;
}
cin >> w;
for (int i = 1;i <= w;i++){
int a, b;
cin >> a >> b;
if (p[a] > p[b]) swap(a, b);
if (p[a].F.F == p[b].F.F){
wall[a][2].F = b;
wall[b][0].F = a;
wall[a][2].S = wall[b][0].S = i;
}
else {
wall[a][1].F = b;
wall[b][3].F = a;
wall[a][1].S = wall[b][3].S = i;
}
}
// for (int i = 1;i <= n;i++)
// cout <<i << ' '<< wall[i][0].F << ' ' << wall[i][1].F << ' '<< wall[i][2].F << ' ' << wall[i][3].F<< endl;
sort (p + 1, p + n + 1);
for (int i = 1;i <= n;i++){
// cout <<"######################\n";
dfs(1, p[i].S);
}
// cout <<"#############################\n";
for (int i = 1;i <= w;i++)
if (!brok[i])
k++;
cout << k<< endl;
for (int i = 1;i <= w;i++)
if (!brok[i])
cout << i << endl;
}
# | 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... |
# | 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... |
# | 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... |