Problem:
Score : 1100 points

Problem Statement

You are given a directed graph with N vertices and M edges.
The vertices are numbered 1, 2, ..., N, and the edges are numbered 1, 2, ..., M.
Edge i points from Vertex a_i to Vertex b_i.

For each edge, determine whether the reversion of that edge would change the number of the strongly connected components in the graph.

Here, the reversion of Edge i means deleting Edge i and then adding a new edge that points from Vertex b_i to Vertex a_i.

Constraints

2 \leq N \leq 1000

1 \leq M \leq 200,000

1 \leq a_i, b_i \leq N

a_i \neq b_i

If i \neq j, then a_i \neq a_j or b_i \neq b_j.

Input

Input is given from Standard Input in the following format:

N M
a_1 b_1
a_2 b_2
:
a_M b_M

Output

Print M lines. In the i-th line, if the reversion of Edge i would change the number of the strongly connected components in the graph, print diff; if it would not, print same.

Sample Input 1

3 3
1 2
1 3
2 3

Sample Output 1

same
diff
same

The number of the strongly connected components is 3 without reversion of edges, but it will become 1 if Edge 2 is reversed.

Sample Input 2

2 2
1 2
2 1

Sample Output 2

diff
diff

Reversion of an edge may result in multiple edges in the graph.

Sample Input 3

5 9
3 2
3 1
4 1
4 2
3 5
5 3
3 4
1 2
2 5

Sample Output 3

same
same
same
same
same
diff
diff
diff
diff

Solution in C++ (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define edge(u) for(re int i=head[u];i;i=e[i].nxt)
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int N=1e3+5;
const int M=2e5+5;
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
bool vis[N],vis1[N][N],vis2[N][N];
int n,m,head[N],cnt,a[M],b[M],mark[N];
struct edge{
	int to,nxt;
}e[M];
void add(int a,int b){
	e[++cnt].to=b;
	e[cnt].nxt=head[a];
	head[a]=cnt;
}
void dfs1(int u,int s){
	vis1[s][u]=1;
	edge(u){
		int v=e[i].to;
		if(!vis1[s][v]) dfs1(v,s);
	}
}
void dfs2(int u,int s,int tp,int c){
	if(!tp) mark[u]=c;
	else vis2[s][u]=c!=mark[u];
	vis[u]=1;
	edge(u){
		int v=e[i].to;
		if(vis[v]) continue;
		dfs2(v,s,tp,c);
	}
}
vector<pair<int,int> > ve;
int main(){
	n=read(),m=read();
	inc(i,1,m){
		a[i]=read(),b[i]=read();
		add(a[i],b[i]);
	}
	inc(i,1,n) dfs1(i,i);
	inc(u,1,n){
		memset(vis,0,sizeof(vis));vis[u]=1;
		edge(u){
			int v=e[i].to;
			ve.push_back(mp(v,i));
			if(vis[v]) continue;
			dfs2(v,u,0,i);
		}
		memset(vis,0,sizeof(vis));vis[u]=1;
		for(re int i=ve.size()-1;i>=0;i--){
			int v=ve[i].fi,c=ve[i].se;
			if(vis[v]) continue;
			dfs2(v,u,1,c);
		}
		ve.clear();
	}
	inc(i,1,m) puts(vis1[b[i]][a[i]]^vis2[a[i]][b[i]]?"diff":"same");
}