Submission #761815

# Submission time Handle Problem Language Result Execution time Memory
761815 2023-06-20T10:05:18 Z YassineBenYounes Bitaro’s Party (JOI18_bitaro) C++17
0 / 100
2000 ms 408 KB
#include<bits/stdc++.h>
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pbds tree<pair<int, int>, null_type, less<pair<int, int>>,rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM)
int dx[8] = {1, 0, 0, -1, 1, 1, -1, -1};
int dy[8] = {0, 1, -1, 0, 1, -1, -1, 1};
#define endl "\n"
#define ss second
#define ff first
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define vi vector<int>
#define vii vector<pair<int,int>>
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd  pair<double,double>
#define vdd  vector<pdd>
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
////////////////////Only Clear Code//////////////////////////

void usaco_problem(){
    freopen("milkvisits.in", "r", stdin);
    freopen("milkvisits.out", "w", stdout);
}

void init(){
    #ifndef ONLINE_JUDGE
 
freopen("input.txt", "r", stdin);
 
freopen("output.txt", "w", stdout);
 
#endif // ONLINE_JUDGE
}

const int mx = 1005;
const int LOG = 25;
const int inf = 1e9+5;
const ll mod = 1e9+7;
const int sq = 0;

vi graph[mx], rgraph[mx];

int dp[mx];

bool busy[mx], vis[mx];

void dfs(int node){
    vis[node] = 1;
    for(int adj : rgraph[node]){
        dp[adj] = max(dp[adj], dp[node]+1);
        dfs(adj);
    }
}
/*
bool compare(const int &a, const int &b){
    return dp[a] > dp[b];
}
*/
void run_case(){
    int n, m, q;cin >> n >> m >> q;
    while(m--){
        int a, b;cin >> a >> b;
        graph[a].pb(b);
        rgraph[b].pb(a);
    }
    while(q--){
        int node;cin >> node;
        int k;cin >> k;
        vi v;
        for(int i = 0; i < k;i++){
            int a;cin >> a;
            busy[a] = 1;
            v.pb(a);
        }
        if(k < sq){

        }
        else{
            int ans = -1;
            memset(dp, -1, sizeof dp);
            memset(vis, 0, sizeof vis);
            dp[node] = 0;
            dfs(node);
            for(int i = 1; i <= n;i++){
                if(busy[i])continue;
                //cout << dp[i] << " ";
                ans = max(ans, dp[i]);
            }
            //cout << endl;
            cout << ans << endl;
        }
        for(int i = 0; i < k;i++){
            busy[v[i]] = 0;
        }
    }
}

int main(){
    speed;
    int t;
    //cin >> t;
    t = 1;
    while(t--){
        run_case();
    }
}

/*
    NEVER GIVE UP!
    DOING SMTHNG IS BETTER THAN DOING NTHNG!!!
    Your Guide when stuck:
    - Continue keyword only after reading the whole input
    - Don't use memset with testcases
    - Check for corner cases(n=1, n=0)
    - Check where you declare n(Be careful of declaring it globally and in main)
*/

Compilation message

bitaro.cpp: In function 'void usaco_problem()':
bitaro.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen("milkvisits.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:34:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     freopen("milkvisits.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp: In function 'void init()':
bitaro.cpp:40:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:42:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 | freopen("output.txt", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 408 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Execution timed out 2072 ms 340 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 408 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Execution timed out 2072 ms 340 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 408 KB Output is correct
7 Correct 1 ms 388 KB Output is correct
8 Execution timed out 2072 ms 340 KB Time limit exceeded
9 Halted 0 ms 0 KB -