Language: C++

#pragma GCC optimize(3)
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,s,m,cnt,tcnt,tot,idx[400010],lt[400010],rt[400010],a[100010],u[100010],p[100010],d[100010],vis[1000010],in[1000010],up[1000010];
vector<int>g[1000010];
inline void add_edge(int u,int v){
	g[u].push_back(v);
	in[v]++;
	return;
}
void build(int o,int l,int r){
	if(l==r){
		idx[o]=l;
		return;
	}
	idx[o]=++cnt;
	lt[idx[o]]=l;
	rt[idx[o]]=r;
	int mid=(l+r)>>1;
	build(o<<1,l,mid);
	build(o<<1|1,mid+1,r);
	add_edge(idx[o],idx[o<<1]);
	add_edge(idx[o],idx[o<<1|1]);
	return;
}
void link(int o,int l,int r,int L,int R,int u){
	if(L<=l&&r<=R){
		add_edge(u,idx[o]);
		return;
	}
	int mid=(l+r)>>1;
	if(L<=mid)
		link(o<<1,l,mid,L,R,u);
	if(R>mid)
		link(o<<1|1,mid+1,r,L,R,u);
	return;
}
inline void bfs(){
	queue<int>q;
	for(register int i=1;i<=n;i++)
		if(!in[i]){
			q.push(i);
			if(up[i]>1e9)
				up[i]=1e9;
			vis[i]=1;
		}
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(auto &v:g[u]){
			if(vis[v]&&((up[v]>=up[u]&&v<=n)||(up[v]>up[u]&&v>n))){
				puts("NIE");
				exit(0);
			}
			if(v<=n)
				up[v]=min(up[v],up[u]-1);
			else
				up[v]=min(up[v],up[u]);
			in[v]--;
			if(!in[v]){
				vis[v]=1;
				q.push(v);
			}
		}
	}
	return;
}
char buffer[10000010],*hd;
inline char Getchar(){
	return *hd++;
}
inline int rd(){
	register int x=0;
	char c;
	do c=Getchar();
	while(!isdigit(c));
	do{
		x=(x<<1)+(x<<3)+(c^48);
		c=Getchar();
	}while(isdigit(c));
	return x;
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("data.in","r",stdin);
	#endif
	fread(buffer,1,10000000,stdin);
	hd=buffer;
	memset(up,127,sizeof(up));
	n=rd(),s=rd(),m=rd();
	for(register int i=1;i<=s;i++){
		p[i]=rd(),d[i]=rd();
		up[p[i]]=d[i];
	}
	cnt=n;
	build(1,1,n);
	tcnt=cnt;
	while(m--){
		int l=rd(),r=rd(),k=rd();
		++cnt;
		for(register int i=1;i<=k;i++){
			u[i]=rd();
			if(i==1){
				if(u[i]>l)
					link(1,1,n,l,u[i]-1,cnt);
			}
			else{
				if(u[i]>u[i-1]+1)
					link(1,1,n,u[i-1]+1,u[i]-1,cnt);
			}
			add_edge(u[i],cnt);
		}
		if(r>u[k])
			link(1,1,n,u[k]+1,r,cnt);
	}
	bfs();
	for(register int i=1;i<=n;i++){
		if(up[i]<1||!vis[i]){
			puts("NIE");
			return 0;
		}
		if(up[i]>1e9)
			up[i]=1e9;
	}
	for(register int i=1;i<=s;i++)
		if(up[p[i]]!=d[i]){
			puts("NIE");
			return 0;
		}
	puts("TAK");
	for(register int i=1;i<=n;i++)
		printf("%d ",up[i]);
	return 0;
}

Compiler output:
a.cc: In function 'void bfs()':
a.cc:43:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   43 |         for(register int i=1;i<=n;i++)
      |                          ^
a.cc: In function 'int rd()':
a.cc:76:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   76 |         register int x=0;
      |                      ^
a.cc:79:16: error: 'isdigit' was not declared in this scope
   79 |         while(!isdigit(c));
      |                ^~~~~~~
a.cc: In function 'int main()':
a.cc:94:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   94 |         for(register int i=1;i<=s;i++){
      |                          ^
a.cc:104:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  104 |                 for(register int i=1;i<=k;i++){
      |                                  ^
a.cc:120:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  120 |         for(register int i=1;i<=n;i++){
      |                          ^
a.cc:128:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  128 |         for(register int i=1;i<=s;i++)
      |                          ^
a.cc:134:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  134 |         for(register int i=1;i<=n;i++)
      |                          ^