比赛 20150424 评测结果 AAAAEEEEEEEEAAA
题目名称 相遇时间 最终得分 46
用户昵称 raywzy 运行时间 4.412 s
代码语言 C++ 内存使用 0.69 MiB
提交时间 2015-04-24 08:40:04
显示代码纯文本
#include<cstdio>
#include<deque>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
int N,M,C,D,E,F;
bool flag=0;
class Node
{
public:
	int x;
	int f;
	int s;
};
vector<Node> A[105];
vector<Node> B[105];
int sa=0,sb=0;
int FA[50000],FB[50000];
void BFS()
{
	deque<Node> Q;
	Node temp,kk,tmp,bb;temp.x=1;temp.s=0;temp.f=0;
	Q.push_back(temp);
	while(!Q.empty())
	{
		temp=Q.at(0);
		Q.pop_front();
		if(temp.x==N)
		{
			FA[temp.f]=1;
			FB[temp.s]=1;
		}
		for(int i=0;i<A[temp.x].size();i++)
		{
			kk=A[temp.x][i];
			bb=B[temp.x][i];
			tmp.x=kk.x;tmp.f=temp.f+kk.s;tmp.s=temp.s+bb.s;
			Q.push_back(tmp);
		}
	}
}
int main()
{
	freopen("meeting.in","r",stdin);
	freopen("meeting.out","w",stdout);
	int i;Node temp;
	scanf("%d%d",&N,&M);
	for(i=1;i<=M;i++)
	{
		scanf("%d%d%d%d",&C,&D,&E,&F);
		temp.x=D,temp.s=E;
		A[C].push_back(temp);
		temp.x=D;temp.s=F;
		B[C].push_back(temp);
	}
	BFS();
	for(i=0;i<40000;i++)
	{
		if(FA[i]==1&&FB[i]==1)
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
		printf("%d\n",i);
	else
		printf("IMPOSSIBLE\n");
	return 0;
}