이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include "bits_stdc++.h"
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%ld%ld%ld%ld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
ll n, m, q, x, y, bound;
vector<ll> radj[100005];
bool ban[100005];
vector<pi> maxdist[100005];
ll dist[100005][2];
void initsqrt() // O(n * sqrt(n))
{
for (ll i=0; i<n; ++i)
{
vector<ll> list;
list.pb(i);
maxdist[i].pb(mp(0, i));
dist[i][0] = 0;
dist[i][1] = i;
for (ll u: radj[i])
{
for (pi x: maxdist[u])
{
if (dist[x.s][1]!=i)
{
list.pb(x.s);
dist[x.s][0] = x.f+1;
dist[x.s][1] = i;
}
else
{
dist[x.s][0] = max(dist[x.s][0], x.f+1);
}
}
}
for (ll u: list) maxdist[i].pb(mp(dist[u][0], u));
sort(maxdist[i].begin(), maxdist[i].end(), greater<pi>());
while (maxdist[i].size()>bound) maxdist[i].pop_back();
}
}
ll dp(ll t) // O(n)
{
ll dp[n];
fill(dp, dp+n, 0);
for (ll i=0; i<=t; ++i)
{
for (ll u: radj[i]) dp[i] = max(dp[i], dp[u]+1);
if (ban[i]&& dp[i]==0 ) dp[i] = -1;
}
return dp[t];
}
int main()
{
input3(n, m, q);
bound = sqrt(n);
for (ll i=0; i<m; ++i)
{
input2(x, y);
x--; y--;
radj[y].pb(x);
}
initsqrt();
while (q--)
{
ll t, y, temp;
input2(t, y);
t--;
fill(ban, ban+n, 0);
for (ll i=0; i<y; ++i) {input(temp);temp--; ban[temp] = true;}
if (y>=bound) {print(dp(t), '\n'); continue;}
ll ans = -1;
for (pi u: maxdist[t])
{
//show(u.s);
if (ban[u.s]) continue;
ans = u.f;
break;
}
print(ans, '\n');
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bitaro.cpp: In function 'void initsqrt()':
bitaro.cpp:63:27: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
63 | while (maxdist[i].size()>bound) maxdist[i].pop_back();
| ~~~~~~~~~~~~~~~~~^~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:13:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:81:2: note: in expansion of macro 'input3'
81 | input3(n, m, q);
| ^~~~~~
bitaro.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define input2(x, y) scanf("%lld%lld", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
bitaro.cpp:85:3: note: in expansion of macro 'input2'
85 | input2(x, y);
| ^~~~~~
bitaro.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define input2(x, y) scanf("%lld%lld", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
bitaro.cpp:93:3: note: in expansion of macro 'input2'
93 | input2(t, y);
| ^~~~~~
bitaro.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | #define input(x) scanf("%lld", &x);
| ~~~~~^~~~~~~~~~~~
bitaro.cpp:96:27: note: in expansion of macro 'input'
96 | for (ll i=0; i<y; ++i) {input(temp);temp--; ban[temp] = true;}
| ^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |