Rikka with Graph
Accepts: 353
Submissions: 1174
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
分析:最短路肯定都是1,如果1和n有边,那么随便从n个节点中找两个连接就可以啊,如果无边,那么连接1-n
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<string.h>
#include<set>
using namespace std;
int main()
{
int n,m,u,v;
while(cin>>n>>m){
bool flag=0;
for(int i=0;i<m;i++){
cin>>u>>v;
if((u==1&&v==n)||(u==n&&v==1))flag=1;
}
if(flag)cout<<"1 "<<n*(n-1)/2<<endl;
else cout<<"1 1"<<endl;
}
return 0;
}