이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("unroll-loops")
#pragma gcc optimize("Ofast")
#pragma GCC optimization("Ofast")
#pragma optimize(Ofast)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
#define str string
#define fs first
#define ss second
#define all(a) a.begin(), a.end()
#define print(a) \
for (auto x : a) \
cout << x << ' '; \
cout << endl;
void __print(signed x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const str &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const array<int, 2> &x)
{
cerr << '{';
__print(x[0]);
cerr << ',';
__print(x[1]);
cerr << '}';
}
template <typename T, typename V>
void __print(const pair<T, V> &x)
{
cerr << '{';
__print(x.fs);
cerr << ',';
__print(x.ss);
cerr << '}';
}
template <typename T>
void __print(const T &x)
{
int f = 0;
cerr << '{';
for (auto &y : x)
cerr << (f++ ? "," : ""), __print(y);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#ifdef ONLINE_JUDGE
#define debug(x...) 42
#endif
const int mod = 1e9 + 7;
void solve()
{
int n, m;
cin >> n >> m;
vector<vector<int>> graph(n + 1), rev_graph(n + 1);
vector<vector<bool>> way(n + 1, vector<bool>(n + 1));
int last = 0;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
if (way[a][b] == 1)
{
cout << last;
if (i < m - 1)
cout << endl;
continue;
}
graph[a].push_back(b);
rev_graph[b].push_back(a);
way[a][b] = 1;
int sz = last + 1;
queue<array<int, 2>> q;
for (auto x : graph[b])
{
if (way[x][b] == 1 and way[b][x] == 1 and way[a][x] == 0 and x != a)
{
way[a][x] = 1;
sz++;
graph[a].push_back(x);
rev_graph[x].push_back(a);
if (way[x][a] == 1)
q.push({a, x});
}
}
if (way[a][b] == 1 and way[b][a] == 1)
q.push({a, b});
while (!q.empty())
{
array<int, 2> v = q.front();
q.pop();
for (auto x : rev_graph[v[0]])
{
if (way[x][v[1]] == 0 and x != v[1])
{
way[x][v[1]] = 1;
sz++;
if (way[v[1]][x] == 1)
q.push({x, v[1]});
else
graph[x].push_back(v[1]);
rev_graph[v[1]].push_back(x);
}
}
for (auto x : rev_graph[v[1]])
{
if (way[x][v[0]] == 0 and x != v[0])
{
way[x][v[0]] = 1;
sz++;
graph[x].push_back(v[0]);
rev_graph[v[0]].push_back(x);
if (way[v[0]][x] == 1)
q.push({x, v[0]});
}
}
}
cout << sz << endl;
last = sz;
}
}
signed main()
{
fastio;
int t = 1;
// cin >> t;
while (t--)
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
foodcourt.cpp:2: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
2 | #pragma gcc optimize("Ofast")
|
foodcourt.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization("Ofast")
|
foodcourt.cpp:4: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
4 | #pragma optimize(Ofast)
|
foodcourt.cpp: In function 'void solve()':
foodcourt.cpp:128:21: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
128 | else
| ^~~~
foodcourt.cpp:130:25: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
130 | rev_graph[v[1]].push_back(x);
| ^~~~~~~~~
# | 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... |