比赛 |
20150424 |
评测结果 |
EEEEEEEEEEEEEEE |
题目名称 |
相遇时间 |
最终得分 |
0 |
用户昵称 |
wolf. |
运行时间 |
1.123 s |
代码语言 |
C++ |
内存使用 |
0.32 MiB |
提交时间 |
2015-04-24 10:07:41 |
显示代码纯文本
#include<iostream>
#include<fstream>
#include<bitset>
#include<vector>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdio>
using namespace std;
#if defined wolf
const string ok="OK";
const string kk=" ";
ofstream nnew("meeting.in",ios::app);
ifstream fin("meeting.in");
#define fout cout
#define Endl endl
#else
ifstream fin("meeting.in");
ofstream fout("meeting.out");
#endif
class llink{
public:
int from,to;
int C,D;
llink(){
}
llink(int a,int b,int c,int d){
from=a;
to=b;
C=c;
D=d;
}
};
vector<vector<int> > index;
vector<llink> TT;
vector<int> AA[105];
vector<int> BB[105];
void work1(int n){
AA[1].push_back(0);
vector<bool> flag;
flag.resize(105,0);
queue<int> Q;
Q.push(1);
while(!Q.empty()){
int it=Q.front();
Q.pop();
flag[it]=0;
for(int i=0;i!=index[it].size();++i){
llink& pp=TT[index[it][i]];
vector<bool> ttime;
ttime.resize(10000,0);
for(int j=0;j!=AA[it].size();++j){
if(ttime[AA[it][i]]){
continue;
}
ttime[AA[it][i]]=1;
AA[pp.to].push_back(AA[it][i]+pp.C);
}
if(flag[pp.to]==0){
flag[pp.to]=1;
Q.push(pp.to);
}
}
}
sort(AA[n].begin(),AA[n].end());
}
void work2(int n){
BB[1].push_back(0);
vector<bool> flag;
flag.resize(105,0);
queue<int> Q;
Q.push(1);
while(!Q.empty()){
int it=Q.front();
Q.pop();
flag[it]=0;
for(int i=0;i!=index[it].size();++i){
llink& pp=TT[index[it][i]];
vector<bool> ttime;
ttime.resize(10000,0);
for(int j=0;j!=BB[it].size();++j){
if(ttime[BB[it][i]]){
continue;
}
BB[pp.to].push_back(BB[it][i]+pp.D);
}
if(flag[pp.to]==0){
flag[pp.to]=1;
Q.push(pp.to);
}
}
}
sort(BB[n].begin(),BB[n].end());
}
int core(int n){
work1(n);
work2(n);
int a=0,b=0;
while(a<AA[n].size()&&b<BB[n].size()){
if(AA[n][a]==BB[n][b]){
return AA[n][a];
}
if(AA[n][a]<BB[n][b]){
++a;
}
if(AA[n][a]>BB[n][b]){
++b;
}
}
return -1;
}
int main(){
int n,m;
fin>>n>>m;
index.resize(n+5);
for(int i=0;i!=m;++i){
int a,b,c,d;
fin>>a>>b>>c>>d;
index[a].push_back(TT.size());
TT.push_back(llink(a,b,c,d));
}
int r=core(n);
if(r==-1){
fout<<"IMPOSSIBLE"<<endl;
}else{
fout<<r<<endl;
}
//-------------------------*/
#if defined wolf
cout<<endl<<(double)clock()/CLOCKS_PER_SEC<<'s'<<endl;
#endif
return 0;
}
//Designed by wolf
//Fri Apr 24 2015