22532023-01-06 08:27:43kohumarkUtazás (40)cpp11Accepted 40/4046ms8084 KiB
// Example program
#include <bits/stdc++.h>
#define speed cin.tie(0);ios::sync_with_stdio(0)
using namespace std;

int main()
{
    speed;
    int n, m, q;
    cin >> n >> m >> q;
    int ind[q]; for(int i=0; i<q; i++){
	cin >> ind[i];
	ind[i]--;
    }
    
    vector<vector<int>> jaratok; int be[n];
    jaratok.assign(n, vector<int>());
    for(int i=0; i<n; i++) be[i]=0;
    for(int i=0; i<m; i++){
	int a, b;
        cin >> a >> b; a--; b--;
	jaratok[a].push_back(b);
	be[b]++;
    }
    
    queue<int> alap; vector<int> vegso;
    for(int i=0; i<n; i++) if(be[i]==0) alap.push(i);

    while(!alap.empty()){
	int next=alap.front();
	alap.pop();
	for(int i : jaratok[next]){
		be[i]--;
		if(be[i]==0){
		       alap.push(i);
		}
	}
	vegso.push_back(next);
    }

    bool win[n+1];
    for(int i=0; i<n+1; i++) win[i]=false;
    for(int i=n-1; i>-1; i--){
	for(int j : jaratok[vegso[i]]){
		win[vegso[i]] |= ! win[j];
	}
    }

    for(int i=0; i<q; i++) cout << (win[ind[i]] ? "A\n" : "B\n");
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1824 KiB
2Accepted0/035ms8084 KiB
3Accepted1/12ms2268 KiB
4Accepted2/22ms2464 KiB
5Accepted1/12ms2632 KiB
6Accepted2/22ms2852 KiB
7Accepted2/23ms3256 KiB
8Accepted2/24ms3960 KiB
9Accepted2/23ms3756 KiB
10Accepted2/24ms3904 KiB
11Accepted2/213ms4684 KiB
12Accepted3/314ms4700 KiB
13Accepted3/314ms4916 KiB
14Accepted3/314ms4932 KiB
15Accepted3/314ms5240 KiB
16Accepted3/314ms5492 KiB
17Accepted3/326ms6416 KiB
18Accepted3/346ms7876 KiB
19Accepted3/346ms8056 KiB