| 记录编号 |
259765 |
评测结果 |
AAAAAAAAAA |
| 题目名称 |
2302.[HZOI 2016]奖学金 |
最终得分 |
100 |
| 用户昵称 |
AntiLeaf |
是否通过 |
通过 |
| 代码语言 |
C++ |
运行时间 |
0.000 s |
| 提交时间 |
2016-05-11 16:40:56 |
内存使用 |
0.00 MiB |
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=10010;
namespace mine{
int __c,__x,__a[110],__i,__j;
bool __neg;
inline int getint(){
__x=__neg=0;
do __c=getchar();while(__c==' '||__c=='\n'||__c=='\r'||__c=='\t');
if(__c=='-'){
__neg=true;
__c=getchar();
}
for(;__c>='0'&&__c<='9';__c=getchar())__x=(__x<<1)+(__x<<3)+(__c^48);
if(__neg)return -__x;
return __x;
}
inline void putint(int __x){
__neg=__x<0;
if(__neg)__x=-__x;
__i=0;
do{
__a[__i++]=__x%10+48;
__x/=10;
}while(__x);
if(__neg)putchar('-');
for(__j=__i-1;__j>=0;__j--)putchar(__a[__j]);
}
}
using namespace mine;
struct edge{
int to,pre,kind;
bool vis;
edge():to(0),pre(-1),vis(false){}
}e[maxn<<1];
void insert(int,int);
void dfs(int);
int last[maxn],len=0,color[maxn]={0},f[maxn]={0},ans=0;
bool ok=true;
int n,m,x,y;
inline int MAIN(){
#define MINE
#ifdef MINE
freopen("reward.in","r",stdin);
freopen("reward.out","w",stdout);
#endif
memset(last,-1,sizeof(last));
n=getint();
m=getint();
for(int i=0;i<m;i++){
x=getint();
y=getint();
insert(x,y);
}
for(int i=1;i<=n;i++){
if(!color[i])dfs(i);
if(!ok){
printf("impossible");
return 0;
}
ans+=f[i];
}
putint(ans+100*n);
return 0;
}
inline void insert(int x,int y){
e[len].to=y;
e[len].pre=last[x];
last[x]=len++;
}
inline void dfs(int x){
color[x]=-1;
for(int i=last[x],y;i!=-1;i=e[i].pre){
y=e[i].to;
if(!color[y])dfs(y);
else if(color[y]<0)ok=false;
if(!ok)return;
f[x]=max(f[x],f[y]+1);
}
color[x]=1;
}
int haha=MAIN();
int main(){;}