#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <cassert>
#include <algorithm>
using namespace std;
void printAdjMatrix(vector<vector<int>>& adjM) {
int n = adjM.size();
for(int i=0; i<n; i++) {
printf("%d:",i);
for(int elem: adjM[i])
printf(" %d",elem);
printf("\n");
}
}
void printAdjList(vector<vector<int>>& adjL) {
int n = adjL.size();
for(int i=0; i<n; i++) {
printf("%d:",i);
for(int elem: adjL[i])
printf(" %d", elem);
printf("\n");
}
}
void printDegree(vector<int>& Deg) {
int n = Deg.size();
for(int i=0; i<n; i++) printf("Deg[%d]=%d ",i,Deg[i]);
printf("\n");
}
bool isSubtask1(vector<int>& u, vector<int>& v) {
int m = u.size();
for(int i=0; i<m; i++)
if (v[i]!=u[i] && v[i]!=u[i]+1) return false;
return true;
}
bool isSubtask2(const int n) { return n <= 15;}
vector<int> subtask2(vector<int>& a, vector<int>& r, vector<int>& u, vector<int>& v) {
int n=a.size(), m=u.size();
vector<int> ans(n,0);
queue<int> q;
vector<vector<int>> adjL(n), adjLRev(n), adjM(n,vector<int>(n));
vector<int> inDeg(n), outDeg(n);
for(int i=0; i<m; i++) {
adjL[u[i]].push_back(v[i]); adjLRev[v[i]].push_back(u[i]);
adjM[u[i]][v[i]] = 1;
inDeg[v[i]]++; outDeg[u[i]]++;
}
for(auto& list: adjL) sort(list.begin(),list.end());
for(auto& list: adjLRev) sort(list.begin(),list.end());
printf("Adjacency Matrix\n"); printAdjMatrix(adjM);
printf("Adjacency List\n"); printAdjList(adjL);
printf("Adjacency List Reverse\n"); printAdjList(adjLRev);
printf("outDegree\n"); printDegree(outDeg);
printf("inDegree\n"); printDegree(inDeg);
// for(int i=0; i<n; i++)
// if(a[i] && r[i] && adj[i][i]) {ans[i]=1; q.push(i);}
// else if (!a[i])
return ans;
}
vector<int> subtask1(vector<int>& a, vector<int>& r, vector<int>& u, vector<int>& v) {
int n = a.size(), m = u.size();
vector<int> ans(n,0);
vector<vector<int>> adj(n,vector<int>(n,0));
for(int i=0; i<m; i++) adj[u[i]][v[i]] = 1;
ans[n-1]=r[n-1];
for(int i=n-2; i>=0; i--)
if (a[i]) {ans[i] = adj[i][i] && r[i] || adj[i][i+1] && ans[i+1];}
else {ans[i] = (adj[i][i]==0 || r[i]) && (adj[i][i+1]==0 || ans[i+1]);}
return ans;
}
vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
vector<int> res(a.size());
int n = a.size(), m = u.size();
vector<vector<int>> adj(n);
for(int i=0; i<m; i++) adj[u[i]].push_back(v[i]);
for(int i=0; i<n; i++) sort(adj[i].begin(),adj[i].end());
if (isSubtask2(n)) return subtask2(a,r,u,v);
if (isSubtask1(u,v)) return subtask1(a,r,u,v);
for(int i=0; i<n; i++) {
cout << i << ": ";
for (const int elem: adj[i])
cout << elem << " ";
cout << endl;
}
for(int i = 0; i < n; i++)
res[i] = i % 2;
return res;
}
int main() {
int n, m;
assert(2 == scanf("%d %d", &n, &m));
vector<int> a(n), r(n), u(m), v(m);
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &a[i]));
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &r[i]));
for(int i = 0; i < m; i++)
assert(2 == scanf("%d %d", &u[i], &v[i]));
vector<int> res = who_wins(a, r, u, v);
for(int i = 0; i < (int)res.size(); i++)
printf(i ? " %d" : "%d", res[i]);
printf("\n");
return 0;
}
Compilation message
train.cpp: In function 'std::vector<int> subtask1(std::vector<int>&, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
train.cpp:82:39: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
82 | if (a[i]) {ans[i] = adj[i][i] && r[i] || adj[i][i+1] && ans[i+1];}
/usr/bin/ld: /tmp/ccymjP61.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc3lphj3.o:train.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status