Problem:
静かな町
アイヅ国では、毎年、駅伝大会が開催されています。アイヅ国には
N
個の町が点在しており、それぞれ 1 から
N
までの番号が付いています。いくつかの町の間は、互いに直接行き来できる道でつながっています。また、どの町の間もいくつかの道を辿って行き来ができます。大会のコースは、次のようにして決めます。
２つの町のすべての組み合わせについて、最短経路の距離を求める。
それらの中で、最短経路の距離が最大になるような２つの町を、スタートの町とゴールの町とする。町の組み合わせが複数ある場合、そのうちのどれか一つを選ぶ。
選ばれたスタートの町とゴールの町の間の最短経路を大会のコースとする。最短経路が複数ある場合、そのうちのどれか一つを選ぶ。
ヤマト国から来たお坊さんのトクイツは、アイヅ国のできるだけ静かな町に新しいお寺を開きたいと考えています。そのため、駅伝大会のコースに使われる可能性がない町を知りたがっています。
アイヅ国の町を結ぶ道の情報が与えられたとき、駅伝大会のコースに使われる可能性がない町を求めるプログラムを作成せよ。
Input
入力は以下の形式で与えられる。
N
R
s
1
t
1
d
1
s
2
t
2
d
2
:
s
R
t
R
d
R
１行目に町の数
N
(2 ≤
N
≤ 1500) と、町の間を直接つなぐ道の数
R
(1 ≤
R
≤ 3000) が与えられる。続く
R
行に２つの町を双方向に直接つなぐ道が与えられる。
s
i
と
t
i
(1 ≤
s
i
<
t
i
≤
N
) は
i
番目の道がつなぐ２つの町の番号を表し、
d
i
(1 ≤
d
i
≤ 1000) はその道の長さを表す。ただし、どの２つの町についても、それらを直接つなぐ道は高々１本とする。
Output
与えられた道の情報に対して、駅伝大会のコースになることがない町をすべて出力する。１行目に駅伝大会のコースになることがない町の数
M
を出力する。続く
M
行に、そのような町の番号を昇順で出力する。
Sample Input 1
4 5
1 2 2
1 3 2
2 3 1
2 4 2
3 4 1
Sample Output 1
1
2
Sample Input 2
7 11
1 2 2
1 3 1
2 4 2
2 5 2
2 6 1
3 4 1
3 5 1
3 6 1
4 7 2
5 7 2
6 7 1
Sample Output 2
3
2
4
5

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int N,M;
    cin>>N>>M;
    vector<vector<pair<int,int>>> G(N);
    for(int i=0;i<M;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }
    int ma = 0;
    {
        for(int i=0;i<N;i++){
            vector<int> dist(N,1e18);
            dist[i] = 0;
            priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
            pq.push({0,i});
            while(!pq.empty()){
                auto [w,u] = pq.top();
                pq.pop();
                for(auto [v,x]:G[u])if(dist[v] > w+x){
                    dist[v] = w+x;
                    pq.push({dist[v],v});
                }
            }
            ma = max(ma,*max_element(dist.begin(),dist.end()));
        }
    }
    set<int> s;
    {
        for(int i=0;i<N;i++){
            vector<int> dist(N,1e18);
            dist[i] = 0;
            priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
            pq.push({0,i});
            while(!pq.empty()){
                auto [w,u] = pq.top();
                pq.pop();
                for(auto [v,x]:G[u])if(dist[v] > w+x){
                    dist[v] = w+x;
                    pq.push({dist[v],v});
                }
            }
            vector<int> dis(N,1e18);
            for(int i=0;i<N;i++)if(dist[i] == ma){
                dis[i] = 0;
                pq.push({0,i});
            }
            while(!pq.empty()){
                auto [w,u] = pq.top();
                pq.pop();
                for(auto [v,x]:G[u])if(dis[v] > w+x){
                    dis[v] = w+x;
                    pq.push({dis[v],v});
                }
            }
            for(int i=0;i<N;i++)if(dist[i]+dis[i] == ma) s.insert(i);
        }
    }
    cout<<N-s.size()<<endl;
    for(int i=0;i<N;i++)if(!s.count(i)) cout<<i+1<<endl;
    //cout<<endl;
}
accuracy: 1
time_ms: 510
memory_kb: 3764
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

using P = pair<int, int>;

struct edge {
    int to, cost;
};

using edges = vector<edge>;
using graph = vector<edges>;

constexpr int INF = 1e9;

vector<int> dijkstra(graph& g, int s, vector<vector<int>>& prev) {
    vector<int> d(g.size(), INF);
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(make_pair(0, s));
    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) {
            continue;
        }
        for(auto& e : g[v]) {
            if(d[e.to] >= d[v] + e.cost) {
                if(d[e.to] > d[v] + e.cost) {
                    prev[e.to].clear();
                }
                prev[e.to].push_back(v);
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
    return d;
}

void dfs(int v, vector<vector<int>> const& prev, set<int>& s) {
    s.insert(v);
    for(auto x : prev[v]) {
        dfs(x, prev, s);
    }
}

int main() {
    int N, R;
    cin >> N >> R;
    graph g(N);
    for(int i=0; i<R; ++i) {
        int s, t, d;
        cin >> s >> t >> d;
        s--; t--;
        g[s].push_back((edge){t, d});
        g[t].push_back((edge){s, d});
    }
    int ma = 0;
    set<int> s;
    for(int i=0; i<N; ++i) {
        vector<vector<int>> prev(N);
        vector<int> d = dijkstra(g, i, prev);
        int max_d = *max_element(d.begin(), d.end());
        if(ma <= max_d) {
            if(ma < max_d) {
                s.clear();
            }
            vector<int> max_v;
            for(int j=0; j<N; ++j) {
                if(d[j] == max_d) {
                    max_v.push_back(j);
                }
            }
            for(auto v : max_v) {
                dfs(v, prev, s);
            }
            ma = max_d;
        }
    }
    cout << N - s.size() << endl;
    for(int i=0; i<N; ++i) {
        if(s.count(i) == 0) {
            cout << i + 1 << endl;
        }
    }
}
accuracy: 1
time_ms: 500
memory_kb: 3728
final_rank: 2

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0351.cc: 静かな町
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 1500;
const int INF = 1 << 30;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

vpii nbrs[MAX_N];
vi ps[MAX_N];
int ds[MAX_N], vs[MAX_N];
bool used[MAX_N], fs[MAX_N];

/* subroutines */

int dijkstra(int n, int st) {
  fill(ds, ds + n, INF);
  ds[st] = 0;
  ps[st].clear();

  priority_queue<pii> q;
  q.push(pii(0, st));

  int maxd = 0, maxu = st;
  while (! q.empty()) {
    auto ue = q.top(); q.pop();
    int ud = -ue.first, u = ue.second;
    if (ds[u] != ud) continue;

    if (maxd < ud) maxd = ud, maxu = u;

    for (auto vw: nbrs[u]) {
      int v = vw.first, vd = ud + vw.second;
      if (ds[v] > vd) {
	ds[v] = vd;
	ps[v].assign(1, u);
	q.push(pii(-vd, v));
      }
      else if (ds[v] == vd)
	ps[v].push_back(u);
    }
  }
  return maxu;
}

/* main */

int main() {
  int n, r;
  scanf("%d%d", &n, &r);

  for (int i = 0; i < r; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--, v--;
    nbrs[u].push_back(pii(v, w));
    nbrs[v].push_back(pii(u, w));
  }

  int t0 = dijkstra(n, 0);
  int t1 = dijkstra(n, t0);
  int dia = ds[t1];
  //printf("t0=%d, t1=%d, dia=%d\n", t0, t1, dia);

  for (int st = 0; st < n; st++) {
    dijkstra(n, st);
    //for (int u = 0; u < n; u++) printf(" %d", ds[u]); putchar('\n');

    fill(used, used + n, false);
    qi q;
    for (int u = 0; u < n; u++)
      if (ds[u] == dia) used[u] = true, q.push(u);
    while (! q.empty()) {
      int u = q.front(); q.pop();
      for (auto v: ps[u])
	if (! used[v]) {
	  used[v] = true;
	  q.push(v);
	}
    }

    for (int u = 0; u < n; u++) fs[u] = fs[u] || used[u];
  }

  int m = 0;
  for (int u = 0; u < n; u++)
    if (! fs[u]) vs[m++] = u;
  
  printf("%d\n", m);
  for (int i = 0; i < m; i++) printf("%d\n", vs[i] + 1);

  return 0;
}
accuracy: 0.25
time_ms: 230
memory_kb: 3144
final_rank: 18

code_snippet: #include <iostream>
#include <queue>
#include <vector>
#include <string.h>
struct E{
	int p;
	long long int c;
	bool operator<(const E& e)const{
		return c>e.c;
	}
};

using namespace std;
long long int dp[1502][1502];
vector<E> gs[1502];
long long int maxlen=0;
void f(int s){
	E e;
	e.p=s;
	e.c=0;
	long long int dp2[1502];
	memset(dp2,-1,sizeof(dp2));
	dp2[s]=0;
	priority_queue<E> pq;
	pq.push(e);
	while(pq.size()>0){
		e=pq.top();
		pq.pop();
		if(dp2[e.p]==-2)continue;
		e.c=dp2[e.p];
		dp[s][e.p]=e.c;
		dp[e.p][s]=e.c;
		if(maxlen<e.c){
			maxlen=e.c;
		}
		dp2[e.p]=-2;
		for(int i=0;i<gs[e.p].size();i++){
			E e2=gs[e.p][i];
			E e3;
			e3.p=e2.p;
			e3.c=e.c+e2.c;
			if(dp2[e2.p]==-1 || dp2[e2.p]>e3.c){
				dp2[e2.p]=e3.c;
				pq.push(e3);
			}
		}
	}
}

int main() {
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b,c;
		E e;
		cin>>a>>b>>e.c;
		e.p=b;
		gs[a].push_back(e);
		e.p=a;
		gs[b].push_back(e);
	}
	for(int s=1;s<=n;s++){
		f(s);
	}
	int ans[1501];
	memset(ans,0,sizeof(ans));
	for(int s=1;s<=n;s++){
		for(int p=1;p<=n;p++){
			if(ans[p]==1)continue;
			for(int g=s+1;g<=n;g++){
				if(dp[s][g]==dp[s][p]+dp[p][g] && dp[s][g]==maxlen){
					ans[p]=1;
					break;
				}
			}
		}
	}
	int ansc=0;
	for(int p=1;p<=n;p++){
		if(ans[p]==0)ansc++;
	}
	cout<<ansc<<endl;
	for(int p=1;p<=n;p++){
		if(ans[p]==0)cout<<p<<endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 1570
memory_kb: 21040
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < int(n); i++)

struct edge{
	int to, cost;
};
using P = pair<int, int>;
using Graph = vector<vector<edge>>;

vector<int> Dijkstra(Graph &g, int s){
	int n = int(g.size());
	const int INF = 1e9;

	vector<int> dist(n, INF);
	dist[s] = 0;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push({0, s});
	while(!que.empty()){
		auto top = que.top();
		que.pop();
		int cost = top.first;
		int at = top.second;
		if(dist[at] < cost) continue;

		for(auto e: g[at]){
			int to = e.to;
			if(dist[to] > cost + e.cost){
				dist[to] = cost + e.cost;
				que.push({dist[to], to});
			}
		}
	}

	return dist;
}

vector<int> dists[1515];

int main(){
	int n, r;
	cin >> n >> r;
	Graph g(n);
	rep(_, r){
		int s, t, d;
		cin >> s >> t >> d;
		s--, t--;

		g[s].push_back({t, d});
		g[t].push_back({s, d});
	}

	int max_d = 0;
	rep(i, n){
		dists[i] = Dijkstra(g, i);
		rep(j, n) max_d = max(max_d, dists[i][j]);
	}

	vector<int> offs;
	rep(i, n) offs.push_back(i);
	rep(s, n){
		vector<int> gs;
		rep(i, s){
			if(dists[s][i] == max_d){
				gs.push_back(i);
			}
		}

		vector<int> outs;
		for(int v: offs){
			for(int g: gs){
				if(dists[s][v] + dists[g][v] == dists[s][g]){
					outs.push_back(v);
					break;
				}
			}
		}

		for(int v: outs){
			offs.erase(find(offs.begin(), offs.end(), v));
		}
	}

	cout << offs.size() << endl;
	for(int v: offs) cout << v + 1 << endl;
}
accuracy: 1
time_ms: 670
memory_kb: 12352
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll=long long;
using P=pair<ll,int>;
constexpr int inf=1e9+10;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep2(i,s,n) for(int i=int(s);i<int(n);i++)

template<typename T>
bool chmax(T &a,T b){
    return (a<b ? a=b,true:false);
}
template<typename T>
bool chmin(T &a,T b){
    return (a>b ? a=b,true:false);
}

struct Q{
    ll a,b;
    Q(ll x,ll y):a(x),b(y){
        ll g=__gcd(a,b);
        a/=g,b/=g;
    }
    Q operator+=(const Q r){
        return (*this)=(*this)+r;
    }
    friend Q operator+(const Q l,const Q r){
        return Q(l.a*r.b+r.a*l.b,l.b*r.b);
    }
    friend Q operator*(const Q l,const Q r){
        return Q(l.a*r.a,l.b*r.b);
    }
    friend ostream& operator<<(ostream &os,Q x){
        os << x.a << '/' << x.b;
        return os;
    }
};
ll pow(int a,int b){
    ll ans=1;
    rep(i,b)ans*=a;
    return ans;
}


int main(){
    cout << fixed << setprecision(20);
    int n,m;
    cin >> n >> m;
    vector<vector<pair<int,int>>> g(n);
    rep(i,m){
        int s,t,d;
        cin >> s >> t >> d;
        s--,t--;
        g[s].emplace_back(t,d);
        g[t].emplace_back(s,d);
    }
    int ans=0;
    vector<bool> res(n,false);
    rep(s,n){
        vector<int> dist(n,inf);
        dist[s]=0;
        priority_queue<P,vector<P>,greater<P>> q;
        q.emplace(0,s);
        while(!q.empty()){
            auto di=q.top();q.pop();
            int d=di.first,i=di.second;
            if(d!=dist[i])continue;
            for(auto p:g[i])if(chmin(dist[p.first],d+p.second)){
                q.emplace(dist[p.first],p.first);
            }
        }

        int mx=0;
        rep(i,n)chmax(mx,dist[i]);
        if(mx < ans)continue;
        if(mx > ans)rep(i,n)res[i]=false;
        chmax(ans,mx);
        vector<bool> now_ans(n,false);
        rep(i,n){
            if(mx==dist[i]){
                now_ans[i]=true;
                queue<int> q;
                q.emplace(i);
                while(!q.empty()){
                    int now=q.front();q.pop();
                    for(auto p:g[now])if(!now_ans[p.first]){
                        if(dist[p.first]+p.second == dist[now]){
                            now_ans[p.first]=true;
                            q.emplace(p.first);
                        }
                    }
                }
            }
        }
        rep(i,n)if(now_ans[i])res[i]=true;
    }
    int cnt=0;
    rep(i,n)if(!res[i])cnt++;
    cout << cnt << endl;
    rep(i,n)if(!res[i])cout << i+1 << endl;;
}
accuracy: 1
time_ms: 280
memory_kb: 3564
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;

using ll=long long;
using P=pair<ll,int>;
constexpr int inf=1e9+10;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep2(i,s,n) for(int i=int(s);i<int(n);i++)

template<typename T>
bool chmax(T &a,T b){
    return (a<b ? a=b,true:false);
}
template<typename T>
bool chmin(T &a,T b){
    return (a>b ? a=b,true:false);
}

struct Q{
    ll a,b;
    Q(ll x,ll y):a(x),b(y){
        ll g=__gcd(a,b);
        a/=g,b/=g;
    }
    Q operator+=(const Q r){
        return (*this)=(*this)+r;
    }
    friend Q operator+(const Q l,const Q r){
        return Q(l.a*r.b+r.a*l.b,l.b*r.b);
    }
    friend Q operator*(const Q l,const Q r){
        return Q(l.a*r.a,l.b*r.b);
    }
    friend ostream& operator<<(ostream &os,Q x){
        os << x.a << '/' << x.b;
        return os;
    }
};
ll pow(int a,int b){
    ll ans=1;
    rep(i,b)ans*=a;
    return ans;
}


int main(){
    cout << fixed << setprecision(20);
    int n,m;
    cin >> n >> m;
    vector<vector<pair<int,int>>> g(n);
    rep(i,m){
        int s,t,d;
        cin >> s >> t >> d;
        s--,t--;
        g[s].emplace_back(t,d);
        g[t].emplace_back(s,d);
    }
    int ans=0;
    vector<bool> res(n,false);
    rep(s,n){
        vector<int> dist(n,inf);
        dist[s]=0;
        priority_queue<P,vector<P>,greater<P>> q;
        q.emplace(0,s);
        while(!q.empty()){
            auto di=q.top();q.pop();
            int d=di.first,i=di.second;
            if(d!=dist[i])continue;
            for(auto p:g[i])if(chmin(dist[p.first],d+p.second)){
                q.emplace(dist[p.first],p.first);
            }
        }

        int mx=0;
        rep(i,n)chmax(mx,dist[i]);
        if(mx < ans)continue;
        if(mx > ans)rep(i,n)res[i]=false;
        vector<bool> now_ans(n,false);
        rep(i,n){
            if(mx==dist[i]){
                now_ans[i]=true;
                queue<int> q;
                q.emplace(i);
                while(!q.empty()){
                    int now=q.front();q.pop();
                    for(auto p:g[now])if(!now_ans[p.first]){
                        if(dist[p.first]+p.second == dist[now]){
                            now_ans[p.first]=true;
                            q.emplace(p.first);
                        }
                    }
                }
            }
        }
        rep(i,n)if(now_ans[i])res[i]=true;
    }
    int cnt=0;
    rep(i,n)if(!res[i])cnt++;
    cout << cnt << endl;
    rep(i,n)if(!res[i])cout << i+1 << endl;;
}
accuracy: 0.25
time_ms: 220
memory_kb: 3520
final_rank: 20

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0351.cc: 静かな町
 */

#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 1500;
const int INF = 1 << 30;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

/* global variables */

vpii nbrs[MAX_N];
vi ps[MAX_N];
int ds[MAX_N], vs[MAX_N];
bool used[MAX_N], zs[MAX_N];

/* subroutines */

int dijkstra(int n, int st) {
  for (int i = 0; i < n; i++) ps[i].clear();
  fill(ds, ds + n, INF);
  ds[st] = 0;

  priority_queue<pii> q;
  q.push(pii(0, st));

  int maxd = 0, maxu = st;
  while (! q.empty()) {
    pii e = q.top(); q.pop();
    int ud = -e.first, u = e.second;
    if (ds[u] != ud) continue;

    if (maxd < ud) maxd = ud, maxu = u;

    for (auto vw: nbrs[u]) {
      int v = vw.first, vd = ud + vw.second;
      if (ds[v] > vd) {
	ds[v] = vd;
	ps[v].clear(), ps[v].push_back(u);
	q.push(pii(-vd, v));
      }
      else if (ds[v] == vd) ps[v].push_back(u);
    }
  }
  return maxu;
}

/* main */

int main() {
  int n, r;
  scanf("%d%d", &n, &r);

  for (int i = 0; i < r; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--, v--;
    nbrs[u].push_back(pii(v, w));
    nbrs[v].push_back(pii(u, w));
  }

  int t0 = dijkstra(n, 0);
  int t1 = dijkstra(n, t0);
  int dia = ds[t1];
  //printf("dia=%d\n", dia);

  for (int st = 0; st < n; st++) {
    fill(used, used + n, false);

    int t = dijkstra(n, st);
    if (ds[t] < dia) continue;

    qi q;
    for (int u = 0; u < n; u++)
      if (ds[u] == dia) used[u] = true, q.push(u);

    while (! q.empty()) {
      int u = q.front(); q.pop();
      for (auto v: ps[u])
	if (! used[v]) used[v] = true, q.push(v);
    }

    for (int u = 0; u < n; u++)
      if (used[u]) zs[u] = true;
  }

  int m = 0;
  for (int u = 0; u < n; u++)
    if (! zs[u]) vs[m++] = u;

  printf("%d\n", m);
  for (int i = 0; i < m; i++) printf("%d\n", vs[i] + 1);
  return 0;
}
accuracy: 0.25
time_ms: 230
memory_kb: 3204
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define LL int
#define PA pair<LL,LL>
#define VE vector
#define VL VE<LL>
#define VVL VE<VL>
#define VP VE<PA>
#define PB push_back
#define MP make_pair
#define PQ priority_queue
#define FI first
#define SE second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000003

template<typename T>bool chmax(T &a,T b){
  if(a<b){
    a=b;
    return 1;
  }
  return 0;
}
template<typename T>bool chmin(T &a,T b){
  if(a>b){
    a=b;
    return 1;
  }
  return 0;
}

typedef struct{
  VP t;LL f,c,n;
}Node;

struct Dijkstra{
  VE<Node> node;
  Dijkstra(LL n){
    node.resize(n);
    rep(i,n)node[i].n=i,node[i].f=-1,node[i].c=INF;
  }
  void add(LL s,LL e,LL c){
    node[s].t.PB(MP(c,e));
  }
  void run(LL s=0,LL c=0){
    LL i;
    PQ<PA,VP,greater<PA>> pq;
    node[s].c=c;
    pq.push(MP(c,s));
    while(pq.size()){
      PA now=pq.top();
      pq.pop();
      LL nowc=now.FI,nown=now.SE;
      if(nowc>node[nown].c)continue;
      for(auto ne:node[nown].t){
        LL nec=nowc+ne.FI,nen=ne.SE;
        if(chmin(node[nen].c,nec))pq.push(MP(nec,nen)),node[nen].f=nown;
      }
    }
  }
};

int main(){
  LL N,R;
  cin>>N>>R;
  LL mx=-1;
  VL ans(N,1),s(R),t(R),d(R);
  Dijkstra D(N);
  rep(i,R){
    cin>>s[i]>>t[i]>>d[i];
    s[i]--,t[i]--;
    D.add(s[i],t[i],d[i]);
    D.add(t[i],s[i],d[i]);
  }
  VVL V(N,VL(N));
  rep(i,N){
    Dijkstra E=D;
    E.run(i);
    rep(j,N)V[i][j]=E.node[j].c,chmax(mx,V[i][j]);
  }
  VP v;
  rep(i,N)for(int j=i+1;j<N;j++)if(V[i][j]==mx)v.PB(MP(i,j)),ans[i]=ans[j]=0;
  VL a;
  rep(i,N)if(ans[i])a.PB(i);
  for(auto p:v){
    VL b;
    for(LL i:a)if(V[p.FI][i]!=mx-V[p.SE][i])b.PB(i);
    a=b;
  }
  cout<<a.size()<<endl;
  for(LL i:a)cout<<i+1<<endl;
}
accuracy: 1
time_ms: 330
memory_kb: 29688
final_rank: 7

code_snippet: #include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define repp(i,n,m) for (int i = m; i < int(n); ++i)
#define repb(i,n) for (int i = int(n)-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;

const string alp = "abcdefghijklmnopqrstuvwxyz";
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
const int INF = 1001001007;
const long long mod1 = 1000000007LL;
const long long mod2 = 998244353LL;
const ll inf = 2e18;
const ld pi = 3.14159265358979323;
const ld eps = 1e-7;
template<typename T>void rev(vector<T> &v){reverse(v.begin(),v.end());}
template<typename T>void sor(vector<T> &v, int f=0){sort(v.begin(),v.end());if(f!=0) rev(v);}
template<typename T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
void dout(ld h=-1.23456789){cout<<setprecision(20);if(abs(h+1.23456789)>eps)cout<<h<<endl;}
template<typename T,typename U> void pout(pair<T,U> p){cout<<p.fi<<" "<<p.se<<endl;}

struct vs{
    vector<pair<int, long long>> to;
};

struct Graph{
    using pli = pair<long long, int>;
    using pil = pair<int, long long>;
    int n, m;
    vector<vs> ar;
    // n : 頂点数 , m : 辺数 , c = 1 : コストを入力 , dual = 1 : 辺が双方向
    Graph(int _n, int _m, int c = 1, int dual = 1) : n(_n), m(_m), ar(n) {
        for (int i = 0; i < m; i++){
            int u, v; cin >> u >> v;
            long long d = 1;
            if (c == 1) cin >> d;
            ar[u-1].to.emplace_back(pil(v-1,d));
            if (dual == 1) ar[v-1].to.emplace_back(pil(u-1,d));
        }
    }
    Graph(vector<vs> _ar, int _n, int _m = 0) : ar(_ar), n(_n), m(_m){}
    vector<long long> dijkstra(int s){
        priority_queue<pli, vector<pli>, greater<pli>> pque;
        vector<long long> dist(n,1e18);
        dist[s] = 0;
        pque.push(pli(0,s));
        while (!pque.empty()){
            pli p = pque.top(); pque.pop();
            if (dist[p.second] < p.first) continue;
            for (pil x : ar[p.second].to){
                if (dist[x.first] > p.first + x.second){
                    dist[x.first] = p.first + x.second;
                    pque.push(pli(dist[x.first],x.first));
                }
            }
        }
        return dist;
    }
    vector<vector<long long>> washall_floyd(){
        vector<vector<long long>> dist(n,vector<long long>(n,2e18));
        for (int i = 0; i < n; i++) dist[i][i] = 0;
        for (int i = 0; i < n; i++){
            for (pil x : ar[i].to){
                dist[i][x.first] = min(dist[i][x.first], x.second);
            }
        }
        for (int k = 0; k < n; k++){
            for (int i = 0; i < n; i++){
                for (int j = 0; j < n; j++){
                    dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
                }
            }
        }
        return dist;
    }
};
int main(){
    int n, r; cin >> n >> r;
    Graph g(n,r);
    vector<vector<ll>> dis(n);
    rep(i,n) dis[i] = g.dijkstra(i);
    ll ma = 0;
    rep(i,n) rep(j,n) chmax(ma,dis[i][j]);
    set<P> st;
    rep(i,n-1) repp(j,n,i+1) if (dis[i][j] == ma) st.insert(P(i,j));
    set<int> cnt;
    for (P p : st) cnt.insert(p.first), cnt.insert(p.second);
    int ans = n - cnt.size();
    vector<int> res;
    rep(i,n){
        if (cnt.find(i) != cnt.end()) continue;
        bool t = false;
        for (P p : st){
            if (dis[p.first][i] + dis[i][p.second] == ma){
                t = true;
                break;
            }
        }
        if (t) ans--;
        else res.emplace_back(i);
    }
    cout << ans << endl;
    rep(i,ans) cout << res[i] + 1 << endl;
}
accuracy: 1
time_ms: 510
memory_kb: 73756
final_rank: 17

code_snippet: #include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,int> >G[1500];
vector<int>D[1500];
vector<int>dijkstra(int st)
{
	vector<int>ret(N,1e9);
	ret[st]=0;
	priority_queue<pair<int,int> >P;
	P.push(make_pair(0,st));
	while(!P.empty())
	{
		int cost=-P.top().first,u=P.top().second;
		P.pop();
		if(ret[u]<cost)continue;
		for(pair<int,int>e:G[u])
		{
			int v=e.first;
			int nxt=cost+e.second;
			if(ret[v]>nxt)
			{
				ret[v]=nxt;
				P.push(make_pair(-nxt,v));
			}
		}
	}
	return ret;
}
bool ok[1500];
bool vis[1500];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		a--,b--;
		G[a].push_back(make_pair(b,c));
		G[b].push_back(make_pair(a,c));
	}
	int dist=0;
	for(int i=0;i<N;i++)
	{
		D[i]=dijkstra(i);
		for(int d:D[i])if(dist<d)dist=d;
	}
	for(int i=0;i<N;i++)ok[i]=true;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)vis[j]=false;
		queue<int>Q;
		for(int j=0;j<N;j++)if(D[i][j]==dist)
		{
			vis[j]=true;
			ok[j]=false;
			Q.push(j);
		}
		while(!Q.empty())
		{
			int u=Q.front();Q.pop();
			for(pair<int,int>e:G[u])
			{
				int v=e.first;
				if(!vis[v]&&D[i][v]+e.second==D[i][u])
				{
					vis[v]=true;
					ok[v]=false;
					Q.push(v);
				}
			}
		}
	}
	vector<int>ans;
	for(int i=0;i<N;i++)if(ok[i])ans.push_back(i);
	cout<<ans.size()<<endl;
	for(int u:ans)cout<<u+1<<endl;
}
accuracy: 1
time_ms: 250
memory_kb: 12044
final_rank: 4

code_snippet: #include<iostream>
#include<vector>
#include<queue>
using namespace std;
int N,M;
vector<pair<int,int> >G[1500];
vector<int>D[1500];
vector<int>dijkstra(int st)
{
	vector<int>ret(N,1e9);
	ret[st]=0;
	priority_queue<pair<int,int> >P;
	P.push(make_pair(0,st));
	while(!P.empty())
	{
		int cost=-P.top().first,u=P.top().second;
		P.pop();
		if(ret[u]<cost)continue;
		for(pair<int,int>e:G[u])
		{
			int v=e.first;
			int nxt=cost+e.second;
			if(ret[v]>nxt)
			{
				ret[v]=nxt;
				P.push(make_pair(-nxt,v));
			}
		}
	}
	return ret;
}
bool ok[1500];
main()
{
	cin>>N>>M;
	for(int i=0;i<M;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		a--,b--;
		G[a].push_back(make_pair(b,c));
		G[b].push_back(make_pair(a,c));
	}
	int dist=0;
	for(int i=0;i<N;i++)
	{
		D[i]=dijkstra(i);
		for(int d:D[i])if(dist<d)dist=d;
	}
	for(int i=0;i<N;i++)ok[i]=true;
	vector<pair<int,int> >E;
	for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)if(D[i][j]==dist)
	{
		ok[i]=ok[j]=false;
		E.push_back(make_pair(i,j));
	}
	vector<int>ans;
	for(int i=0;i<N;i++)if(ok[i])
	{
		bool out=false;
		for(pair<int,int>e:E)if(D[i][e.first]+D[i][e.second]==dist)
		{
			out=true;
			break;
		}
		if(!out)ans.push_back(i+1);
	}
	cout<<ans.size()<<endl;
	for(int u:ans)cout<<u<<endl;
}
accuracy: 1
time_ms: 250
memory_kb: 28224
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

LL GCD(LL a,LL b){ return b?GCD(b,a%b):a; }

struct Edge{
 int to,d;
};

struct DistBuf{
 int D[1500];
 int RD[1500];
};

struct QueNode{
 int to,d;
 bool operator<(QueNode r)const{ return d>r.d; }
};

int N,M;
vector<Edge> E[1500];
DistBuf D[1500];
int F[1500];

int main() {
 cin>>N>>M;
 rep(i,M){
  int s,t,d; cin>>s>>t>>d; s--; t--;
  E[s].push_back({t,d});
  E[t].push_back({s,d});
 }

 {
  priority_queue<QueNode> G;
  rep(s,N){
   rep(to,N){ D[s].D[to]=-1; }
   G.push({s,0});
   while(G.size()){
    int p=G.top().to;
    int d=G.top().d;
    G.pop();
    if(D[s].D[p]!=-1) continue;
    D[s].D[p]=d;
    for(Edge e : E[p])
     G.push({e.to, d+e.d});
   }
  }
 }

 int maxD = 0;
 rep(i,N) rep(j,N) maxD=max(maxD, D[i].D[j]);

 rep(i,N) F[i]=0;

 {
  priority_queue<QueNode> G;
  rep(s,N){
   rep(to,N){ D[s].RD[to]=-1; }
   rep(to,N) if(D[s].D[to]==maxD) G.push({to,0});
   while(G.size()){
    int p=G.top().to;
    int d=G.top().d;
    G.pop();
    if(D[s].RD[p]!=-1) continue;
    D[s].RD[p]=d;
    for(Edge e : E[p])
     G.push({e.to, d+e.d});
   }
  }
 }

 rep(i,N) rep(j,N) if(D[i].D[j]+D[i].RD[j] == maxD) F[j]=1;

 vector<int> ans;
 rep(i,N) if(!F[i]) ans.push_back(i+1);
 cout<<ans.size()<<endl;
 for(int a:ans) cout<<a<<endl;

 return 0;
}
accuracy: 1
time_ms: 810
memory_kb: 20976
final_rank: 8

code_snippet: #include <bits/stdc++.h>

using namespace std;

int N,R;
vector<vector<pair<int, int> > > MapData;
int ShortDistOfEachNode[1501][1501];
bool Used[1501];
set<int> Result;

const int INF = 1e9;

void findShortDistOfEachNode(int StartNode, int *dist) {
	int curNode, cost, sizeOfTo, nextNode, costTo;
	priority_queue<pair<int, int> > NodeList;
	pair<int, int> tmp;

	for (int i = 1; i <= N; ++i) {
		fill(dist, dist + N + 1, INF);
	}
	dist[StartNode] = 0;
	NodeList.push({ StartNode,0 });
	while (!NodeList.empty()) {
		tmp = NodeList.top();
		NodeList.pop();

		curNode = tmp.first;
		cost = tmp.second;
		if (cost > dist[curNode]) {
			continue;
		}
		sizeOfTo = MapData[curNode].size();
		for (int i = 0; i < sizeOfTo; ++i) {
			nextNode = MapData[curNode][i].first;
			costTo = MapData[curNode][i].second;
			if (cost + costTo < dist[nextNode]) {
				dist[nextNode] = cost + costTo;
				NodeList.push({ nextNode,dist[nextNode] });
			}
		}

	}
}

void findNode(int startNode, int curNode, int *dist) {
	int sizeOfTo, preNode, cost;

	if (Used[curNode]) {
		return;
	}
	Used[curNode] = true;
	Result.insert(curNode);
	if (startNode == curNode) {
		return;
	}

	sizeOfTo = MapData[curNode].size();
	for (int i = 0; i < sizeOfTo; ++i) {
		preNode = MapData[curNode][i].first;
		cost = MapData[curNode][i].second;
		if (dist[curNode] == dist[preNode] + cost) {
			findNode(startNode, preNode, dist);
		}
	}
}

int main() {
	int s, t, d, maxShortLen;

	cin >> N >> R;
	MapData.resize(N + 1);
	for (int i = 0; i < R; ++i) {
		cin >> s >> t >> d;
		MapData[s].push_back({ t,d });
		MapData[t].push_back({ s,d });
	}
	for (int i = 1; i <= N; ++i) {
		findShortDistOfEachNode(i,ShortDistOfEachNode[i]);
	}
	
	maxShortLen = 0;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == INF) {
				continue;
			}
			maxShortLen = max(maxShortLen, ShortDistOfEachNode[i][j]);
		}
	}

	for (int i = 1; i <= N; ++i) {
		memset(Used, false, sizeof(Used));
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == maxShortLen) {
				findNode(i, j, ShortDistOfEachNode[i]);
			}
		}
	}

	cout << N - Result.size() << endl;
	for (int i = 1; i <= N; ++i) {
		if (Result.find(i) == Result.end()) {
			cout << i << endl;
		}
	}

	return 0;
}
accuracy: 1
time_ms: 1820
memory_kb: 12096
final_rank: 13

code_snippet: #include <bits/stdc++.h>

using namespace std;

int N,R;
vector<vector<pair<int, int> > > MapData;
vector<pair<int, int> > CourseInfo;
int ShortDistOfEachNode[1501][1501];
bool Used[1501];
set<int> Result;

const int INF = 1e9;

void findShortDistOfEachNode(int StartNode, int *dist) {
	int curNode, cost, sizeOfTo, nextNode, costTo;
	priority_queue<pair<int, int> > NodeList;
	//priority_queue<pair<int, int>,vector<pair<int, int> >,greater<pair<int, int> > > NodeList;
	pair<int, int> tmp;

	for (int i = 1; i <= N; ++i) {
		fill(dist, dist + N + 1, INF);
	}
	dist[StartNode] = 0;
	NodeList.push({ StartNode,0 });
	while (!NodeList.empty()) {
		tmp = NodeList.top();
		NodeList.pop();

		curNode = tmp.first;
		cost = tmp.second;
		if (cost > dist[curNode]) {
			continue;
		}
		sizeOfTo = MapData[curNode].size();
		for (int i = 0; i < sizeOfTo; ++i) {
			nextNode = MapData[curNode][i].first;
			costTo = MapData[curNode][i].second;
			if (cost + costTo < dist[nextNode]) {
				dist[nextNode] = cost + costTo;
				NodeList.push({ nextNode,dist[nextNode] });
			}
		}

	}
}

void findNode(int startNode, int curNode, int *dist) {
	int sizeOfTo, preNode, cost;

	if (Used[curNode]) {
		return;
	}
	Used[curNode] = true;
	Result.insert(curNode);
	/*if (startNode == curNode) {
		return;
	}*/

	sizeOfTo = MapData[curNode].size();
	for (int i = 0; i < sizeOfTo; ++i) {
		preNode = MapData[curNode][i].first;
		cost = MapData[curNode][i].second;
		if (dist[curNode] == dist[preNode] + cost) {
			findNode(startNode, preNode, dist);
		}
	}
}

int main() {
	int s, t, d, maxShortLen;

	cin >> N >> R;
	MapData.resize(N + 1);
	for (int i = 0; i < R; ++i) {
		cin >> s >> t >> d;
		MapData[s].push_back({ t,d });
		MapData[t].push_back({ s,d });
	}
	for (int i = 1; i <= N; ++i) {
		findShortDistOfEachNode(i,ShortDistOfEachNode[i]);
	}
	
	maxShortLen = 0;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == INF) {
				continue;
			}
			maxShortLen = max(maxShortLen, ShortDistOfEachNode[i][j]);
		}
	}

	for (int i = 1; i <= N; ++i) {
		memset(Used, false, sizeof(Used));
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == maxShortLen) {
				findNode(i, j, ShortDistOfEachNode[i]);
			}
		}
	}

	cout << N - Result.size() << endl;
	for (int i = 1; i <= N; ++i) {
		/*if (Result.find(i) == Result.end()) {
			cout << i << endl;
		}*/
		if (Result.count(i) == 0) {
			cout << i << endl;
		}
	}

	return 0;
}
accuracy: 1
time_ms: 1820
memory_kb: 12044
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

int N,R;
vector<vector<pair<int, int> > > MapData;
vector<pair<int, int> > CourseInfo;
int ShortDistOfEachNode[1501][1501];
bool Used[1501];
set<int> Result;

const int INF = 1e9;

void findShortDistOfEachNode(int StartNode, int *dist) {
	int curNode, cost, sizeOfTo, nextNode, costTo;
	priority_queue<pair<int, int> > NodeList;
	//priority_queue<pair<int, int>,vector<pair<int, int> >,greater<pair<int, int> > > NodeList;
	pair<int, int> tmp;

	for (int i = 1; i <= N; ++i) {
		fill(dist, dist + N + 1, INF);
	}
	dist[StartNode] = 0;
	NodeList.push({ StartNode,0 });
	while (!NodeList.empty()) {
		tmp = NodeList.top();
		NodeList.pop();

		curNode = tmp.first;
		cost = tmp.second;
		if (cost > dist[curNode]) {
			continue;
		}
		sizeOfTo = MapData[curNode].size();
		for (int i = 0; i < sizeOfTo; ++i) {
			nextNode = MapData[curNode][i].first;
			costTo = MapData[curNode][i].second;
			if (cost + costTo < dist[nextNode]) {
				dist[nextNode] = cost + costTo;
				NodeList.push({ nextNode,dist[nextNode] });
			}
		}

	}
}

void findNode(int startNode, int curNode, int *dist) {
	int sizeOfTo, preNode, cost;

	if (Used[curNode]) {
		return;
	}
	Used[curNode] = true;
	Result.insert(curNode);
	/*if (startNode == curNode) {
		return;
	}*/

	sizeOfTo = MapData[curNode].size();
	for (int i = 0; i < sizeOfTo; ++i) {
		preNode = MapData[curNode][i].first;
		cost = MapData[curNode][i].second;
		if (dist[curNode] == dist[preNode] + cost) {
			findNode(startNode, preNode, dist);
		}
	}
}

int main() {
	int s, t, d, maxShortLen;

	cin >> N >> R;
	MapData.resize(N + 1);
	for (int i = 0; i < R; ++i) {
		cin >> s >> t >> d;
		MapData[s].push_back({ t,d });
		MapData[t].push_back({ s,d });
	}
	for (int i = 1; i <= N; ++i) {
		findShortDistOfEachNode(i,ShortDistOfEachNode[i]);
	}
	
	maxShortLen = 0;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == INF) {
				continue;
			}
			maxShortLen = max(maxShortLen, ShortDistOfEachNode[i][j]);
		}
	}

	for (int i = 1; i <= N; ++i) {
		memset(Used, false, sizeof(Used));
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == maxShortLen) {
				findNode(i, j, ShortDistOfEachNode[i]);
			}
		}
	}

	cout << N - Result.size() << endl;
	for (int i = 1; i <= N; ++i) {
		if (Result.find(i) == Result.end()) {
			cout << i << endl;
		}
	}

	return 0;
}
accuracy: 1
time_ms: 1820
memory_kb: 12076
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;

int N,R;
vector<vector<pair<int, int> > > MapData;
vector<pair<int, int> > CourseInfo;
int ShortDistOfEachNode[1501][1501];
bool Used[1501];
set<int> Result;

const int INF = 1e9;

void findShortDistOfEachNode(int StartNode, int *dist) {
	int curNode, cost, sizeOfTo, nextNode, costTo;
	priority_queue<pair<int, int> > NodeList;
	//priority_queue<pair<int, int>,vector<pair<int, int> >,greater<pair<int, int> > > NodeList;
	pair<int, int> tmp;

	for (int i = 1; i <= N; ++i) {
		fill(dist, dist + N + 1, INF);
	}
	dist[StartNode] = 0;
	NodeList.push({ StartNode,0 });
	while (!NodeList.empty()) {
		tmp = NodeList.top();
		NodeList.pop();

		curNode = tmp.first;
		cost = tmp.second;
		if (cost > dist[curNode]) {
			continue;
		}
		sizeOfTo = MapData[curNode].size();
		for (int i = 0; i < sizeOfTo; ++i) {
			nextNode = MapData[curNode][i].first;
			costTo = MapData[curNode][i].second;
			if (cost + costTo < dist[nextNode]) {
				dist[nextNode] = cost + costTo;
				NodeList.push({ nextNode,dist[nextNode] });
			}
		}

	}
}

void findNode(int startNode, int curNode, int *dist) {
	int sizeOfTo, preNode, cost;

	if (Used[curNode]) {
		return;
	}
	Used[curNode] = true;
	Result.insert(curNode);
	if (startNode == curNode) {
		return;
	}

	sizeOfTo = MapData[curNode].size();
	for (int i = 0; i < sizeOfTo; ++i) {
		preNode = MapData[curNode][i].first;
		cost = MapData[curNode][i].second;
		if (dist[curNode] == dist[preNode] + cost) {
			findNode(startNode, preNode, dist);
		}
	}
}

int main() {
	int s, t, d, maxShortLen;

	cin >> N >> R;
	MapData.resize(N + 1);
	for (int i = 0; i < R; ++i) {
		cin >> s >> t >> d;
		MapData[s].push_back({ t,d });
		MapData[t].push_back({ s,d });
	}
	for (int i = 1; i <= N; ++i) {
		findShortDistOfEachNode(i,ShortDistOfEachNode[i]);
	}
	
	maxShortLen = 0;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == INF) {
				continue;
			}
			maxShortLen = max(maxShortLen, ShortDistOfEachNode[i][j]);
		}
	}

	for (int i = 1; i <= N; ++i) {
		memset(Used, false, sizeof(Used));
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == maxShortLen) {
				findNode(i, j, ShortDistOfEachNode[i]);
			}
		}
	}

	cout << N - Result.size() << endl;
	for (int i = 1; i <= N; ++i) {
		if (Result.find(i) == Result.end()) {
			cout << i << endl;
		}
	}

	return 0;
}
accuracy: 1
time_ms: 1890
memory_kb: 12108
final_rank: 15

code_snippet: #include <bits/stdc++.h>

using namespace std;

int N,R;
vector<vector<pair<int, int> > > MapData;
vector<pair<int, int> > CourseInfo;
int ShortDistOfEachNode[1501][1501];
bool Used[1501];
set<int> Result;

const int INF = 1e9;

void findShortDistOfEachNode(int StartNode, int *dist) {
	int curNode, cost, sizeOfTo, nextNode, costTo;
	//priority_queue<pair<int, int> > NodeList;
	priority_queue<pair<int, int>,vector<pair<int, int> >,greater<pair<int, int> > > NodeList;
	pair<int, int> tmp;

	for (int i = 1; i <= N; ++i) {
		fill(dist, dist + N + 1, INF);
	}
	dist[StartNode] = 0;
	NodeList.push({ StartNode,0 });
	while (!NodeList.empty()) {
		tmp = NodeList.top();
		NodeList.pop();

		curNode = tmp.first;
		cost = tmp.second;
		if (cost > dist[curNode]) {
			continue;
		}
		sizeOfTo = MapData[curNode].size();
		for (int i = 0; i < sizeOfTo; ++i) {
			nextNode = MapData[curNode][i].first;
			costTo = MapData[curNode][i].second;
			if (cost + costTo < dist[nextNode]) {
				dist[nextNode] = cost + costTo;
				NodeList.push({ nextNode,dist[nextNode] });
			}
		}

	}
}

void findNode(int startNode, int curNode, int *dist) {
	int sizeOfTo, preNode, cost;

	if (Used[curNode]) {
		return;
	}
	Used[curNode] = true;
	Result.insert(curNode);
	if (startNode == curNode) {
		return;
	}

	sizeOfTo = MapData[curNode].size();
	for (int i = 0; i < sizeOfTo; ++i) {
		preNode = MapData[curNode][i].first;
		cost = MapData[curNode][i].second;
		if (dist[curNode] == dist[preNode] + cost) {
			findNode(startNode, preNode, dist);
		}
	}
}

int main() {
	int s, t, d, maxShortLen;

	cin >> N >> R;
	MapData.resize(N + 1);
	for (int i = 0; i < R; ++i) {
		cin >> s >> t >> d;
		MapData[s].push_back({ t,d });
		MapData[t].push_back({ s,d });
	}
	for (int i = 1; i <= N; ++i) {
		findShortDistOfEachNode(i,ShortDistOfEachNode[i]);
	}
	
	maxShortLen = 0;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == INF) {
				continue;
			}
			maxShortLen = max(maxShortLen, ShortDistOfEachNode[i][j]);
		}
	}

	for (int i = 1; i <= N; ++i) {
		memset(Used, false, sizeof(Used));
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == maxShortLen) {
				findNode(i, j, ShortDistOfEachNode[i]);
			}
		}
	}

	cout << N - Result.size() << endl;
	for (int i = 1; i <= N; ++i) {
		if (Result.find(i) == Result.end()) {
			cout << i << endl;
		}
	}

	return 0;
}
accuracy: 1
time_ms: 2470
memory_kb: 12144
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;

int N,R;
vector<vector<pair<int, int> > > MapData;
vector<pair<int, int> > CourseInfo;
int ShortDistOfEachNode[1501][1501];
bool Used[1501];
set<int> Result;

const int INF = 1e9;

void findShortDistOfEachNode(int StartNode, int *dist) {
	int curNode, cost, sizeOfTo, nextNode, costTo;
	priority_queue<pair<int, int> > NodeList;
	pair<int, int> tmp;

	for (int i = 1; i <= N; ++i) {
		fill(dist, dist + N + 1, INF);
	}
	dist[StartNode] = 0;
	NodeList.push({ StartNode,0 });
	while (!NodeList.empty()) {
		tmp = NodeList.top();
		NodeList.pop();

		curNode = tmp.first;
		cost = tmp.second;
		if (cost > dist[curNode]) {
			continue;
		}
		sizeOfTo = MapData[curNode].size();
		for (int i = 0; i < sizeOfTo; ++i) {
			nextNode = MapData[curNode][i].first;
			costTo = MapData[curNode][i].second;
			if (cost + costTo < dist[nextNode]) {
				dist[nextNode] = cost + costTo;
				NodeList.push({ nextNode,dist[nextNode] });
			}
		}

	}
}

void findNode(int startNode, int curNode, int *dist) {
	int sizeOfTo, preNode, cost;

	if (Used[curNode]) {
		return;
	}
	Used[curNode] = true;
	Result.insert(curNode);
	if (startNode == curNode) {
		return;
	}

	sizeOfTo = MapData[curNode].size();
	for (int i = 0; i < sizeOfTo; ++i) {
		preNode = MapData[curNode][i].first;
		cost = MapData[curNode][i].second;
		if (dist[curNode] == dist[preNode] + cost) {
			findNode(startNode, preNode, dist);
		}
	}
}

int main() {
	int s, t, d, maxShortLen;

	cin >> N >> R;
	MapData.resize(N + 1);
	for (int i = 0; i < R; ++i) {
		cin >> s >> t >> d;
		MapData[s].push_back({ t,d });
		MapData[t].push_back({ s,d });
	}
	for (int i = 1; i <= N; ++i) {
		findShortDistOfEachNode(i,ShortDistOfEachNode[i]);
	}
	
	maxShortLen = 0;
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == INF) {
				continue;
			}
			maxShortLen = max(maxShortLen, ShortDistOfEachNode[i][j]);
		}
	}

	for (int i = 1; i <= N; ++i) {
		memset(Used, false, sizeof(Used));
		for (int j = 1; j <= N; ++j) {
			if (ShortDistOfEachNode[i][j] == maxShortLen) {
				findNode(i, j, ShortDistOfEachNode[i]);
			}
		}
	}

	cout << N - Result.size() << endl;
	for (int i = 1; i <= N; ++i) {
		if (Result.find(i) == Result.end()) {
			cout << i << endl;
		}
	}

	return 0;
}
accuracy: 1
time_ms: 1820
memory_kb: 12072
final_rank: 11

code_snippet: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <typename T>
struct edge {
    int from, to; T cost;
    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}
};

template <class K, class V>
class RadixHeap {
    static constexpr int bit_length = sizeof(K)*8;
    K last;
    size_t sz, cnt;

    array<vector<pair<K, V>>, bit_length> v;
    static inline int bsr(int x){
        return x ? bit_length-__builtin_clz(x) : 0;
    }
    static inline int bsr(ll x){
        return x ? bit_length-__builtin_clzll(x) : 0;
    }

    void pull() {
        if(cnt < v[0].size()) return;;
        int i = 1;
        while(v[i].empty()) i++;
        last = min_element(v[i].begin(),v[i].end())->first;
        for (auto &&x : v[i]) v[bsr(x.first ^ last)].push_back(x);
        v[i].clear();
    }
public:
    RadixHeap() : last(0), sz(0), cnt(0) {}
    void emplace(K x, V val){
        sz++;
        v[bsr(x^last)].emplace_back(x, val);
    }

    pair<K, V> top() {
        pull();
        return v[0][cnt];
    }

    void pop() {
        pull();
        sz--;
        cnt++;
    }

    size_t size() const { return sz; }
    bool empty() const { return !sz; }
};

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }


int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<edge<int>>> G(n);
    for (int i = 0; i < m; ++i) {
        int s, t, d;
        scanf("%d %d %d", &s, &t, &d);
        s--; t--;
        G[s].emplace_back(t, d);
        G[t].emplace_back(s, d);
    }
    RadixHeap<int, int> Q;
    auto d = make_v(n, n, INF<int>);
    vector<int> ok(n, 1);
    for (int s = 0; s < n; ++s) {
        d[s][s] = 0;
        Q.emplace(0, s);
        while(!Q.empty()){
            int cost; int i;
            tie(cost, i) = Q.top(); Q.pop();
            if(d[s][i] < cost) continue;
            for (auto &&e : G[i]) {
                auto cost2 = cost + e.cost;
                if(d[s][e.to] <= cost2) continue;
                d[s][e.to] = cost2;
                Q.emplace(d[s][e.to], e.to);
            }
        }
    }
    int val = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            chmax(val, d[i][j]);
        }
    }
    for (int i = 0; i < n; ++i) {
        queue<int> q;
        vector<int> visited(n);
        for (int j = 0; j < n; ++j) {
            if(d[i][j] == val){
                q.emplace(j);
                visited[j] = 1;
            }
        }
        while(!q.empty()){
            int x = q.front(); q.pop();
            ok[x] = 0;
            for (auto &&y : G[x]) {
                if(!visited[y.to] && d[i][y.to]+y.cost == d[i][x]){
                    q.emplace(y.to);
                    visited[y.to] = 1;
                }
            }
        }
    }
    cout << accumulate(ok.begin(),ok.end(), 0) << "\n";
    for (int i = 0; i < n; ++i) {
        if(ok[i]) cout << i+1 << "\n";
    }
    return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 45024
final_rank: 9