제출 #1367494

#제출 시각아이디문제언어결과실행 시간메모리
1367494CowTheCowRegions (IOI09_regions)C++20
30 / 100
514 ms25008 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define double long double
#define vi vector<int>
#define pb push_back
#define sz(a) a.size()
#define pii pair<int,int>
#define fi first
#define se second
#define all(a) a.begin(), a.end()

void setIO(string s) {
	freopen((s + ".in").c_str(), "r", stdin);
	freopen((s + ".out").c_str(), "w", stdout);
}

const int MAXN=2e5+1;
const int MAXR=501; //use this maxR instead, get 30

int n,r,q;
int br;

vi adj [MAXN];
int sz [MAXN] {0};
int get_region [MAXN] {0};
int subtree [MAXR][MAXR];

int dfs(int v, int p, int tar) {
    int sub_cnt=0;

    if(get_region[v]==tar)
        sub_cnt++;

    for(int to:adj[v]) 
        sub_cnt+=dfs(to, v, tar);

    subtree[get_region[v]][tar]+=sub_cnt;
    return sub_cnt;
}

void solve() {

    cin>>n>>r>>q;

    cin>>get_region[1];
    sz[get_region[1]]++;

    for(int i=2;i<=n;i++) {
        int p,r;
        cin>>p>>r;
        get_region[i]=r;
        sz[get_region[i]]++;

        adj[p].pb(i);
    }

    //for each big region, we can just DFS, for each other node we can find how many of its children
    //are kept or ancestors
    for(int i=1;i<=r;i++) 
        dfs(1,-1,i);
    
    for(int i=1;i<=q;i++) {
        int u,v;
        cin>>u>>v;

        cout<<subtree[u][v]<<"\n";
        cout.flush();
    }
}

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t=1;
    // cin>>t;

    while(t>0) {
        solve();
        t--;
    }
}

컴파일 시 표준 에러 (stderr) 메시지

regions.cpp: In function 'void setIO(std::string)':
regions.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen((s + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
regions.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen((s + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…